Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript deleting the array of elements

Tags:

javascript

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

like image 921
g sundrar Avatar asked May 05 '26 02:05

g sundrar


1 Answers

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;
}
like image 127
RoToRa Avatar answered May 07 '26 17:05

RoToRa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!