javascript - If I have multiple checkboxes in a form how can I pass all the checkboxes that are currently checked? -
this code:
<form action="test.php" method="post"> <input type="checkbox" value="value 1" onclick="updatecards(this.value);"> <input type="checkbox" value="value 2" onclick="updatecards(this.value);"> <input type="checkbox" value="value 3" onclick="updatecards(this.value);"> <input type="checkbox" value="value 4" onclick="updatecards(this.value);"> <input type="checkbox" value="value 5" onclick="updatecards(this.value);"> </form>
how can checkboxes checked?
try
<form id="myform" action="test.php" method="post">
then
function getchcked(){ var form = document.getelementbyid('myform'); var chks = form.queryselectorall('input[type="checkbox"]'); var checked = []; for(var = 0; < chks.length; i++){ if(chks[i].checked){ checked.push(chks[i].value) } } return checked; }
demo: fiddle
Comments
Post a Comment