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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -