i am having 10 check boxes.if i click the value of the check box has to push to the array,if i unchecked the check box then the corresponding check box value has to be deleted from the array? pls...anyone give reply for this
Does this have to work exactly like this? It would be easier to generate an array of values from the checked checkboxes when needed.
Something like:
// Pass reference to a parent element of all checkboxes, for example the form
function getCheckedBoxes(parent) {
var result = [];
var inputs = parent.getElementsByTagName("input");
for (var i = 0, len = inputs.length; i < len; i++) {
var cb = inputs[i];
if (cb.type.toLowerCase() === "checkbox" && cb.checked)
result.push(cb.value);
}
return result;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With