This code disables some fields of the form if the checkbox is selected. These disablable* fields are based on the same input NAME (shipping[]). It works, but I need it to be based on the ID (disableme) of the field instead as I require the fields name for processing,
anyone care to shed some light on what I need to do? (Yes, I am asking someone to help do the work for me because I don't have enough time to learn basic javascript this week : )
<script type="text/javascript">
function disableHandler (form, inputName) {
var inputs = form.elements[inputName];
for (var i = 0; i < inputs.length; i++) {
var input = inputs[i];
input.onclick = function (evt) {
if (this.checked) {
disableInputs(this, inputs);
} else {
enableInputs(this, inputs);
}
return true;
};
}
}
function disableInputs (input, inputs) {
for (var i = 0; i < inputs.length; i++) {
var currentInput = inputs[i];
if (currentInput != input) {
currentInput.disabled = true;
}
}
}
function enableInputs (input, inputs) {
for (var i = 0; i < inputs.length; i++) {
var currentInput = inputs[i];
if (currentInput != input) {
currentInput.disabled = false;
}
}
}
</script>
<form name="shippinginformation" action="">
Same as customer information? <input type="checkbox" name="shipping[]" id="disableme" /><br />
Name: <input type="text" name="shipping[]" id="disableme" /><br />
Email: <input type="text" name="shipping[]" id="disableme" /><br />
etc..
</form>
<script type="text/javascript">
disableHandler(document.forms.shippinginformation, 'shipping[]');
</script>
I could just put some text and say, "If your shipping address is the same as your customer address, leave the following forms blank." But as a user myself, I like when things get disabled.
*disablable, is that a word?