javascript - How to show an alert if all checkboxes aren't checked? -


i want alert if check-box not checked (- working )

and

alert if all check-box not checked ( need in )

checkbox :

<input type="checkbox" value="1" id="data" name="data[]"> <input type="checkbox" value="2" id="data" name="data[]"> <input type="checkbox" value="3" id="data" name="data[]"> 

button :

<input name=\"submitclose\" type=\"submit\"  value=\"close\" id=\"submitclose\"> 

below jquery :

echo "<script> jquery(function($)  { $(\"input[id='submitclose']\").click(function() {                    var count_checked = $(\"[id='data']:checked\").length;                  if (count_checked == 0)  {                         alert(\"please select packet(s) close.\");                         return false;                 } else{                              return confirm(\"are sure want close these packet?\");                 }           }); });  </script>"; 

try,

html:

<input type="checkbox" value="1" id="data1" name="data[]"> <input type="checkbox" value="2" id="data2" name="data[]"> <input type="checkbox" value="3" id="data3" name="data[]"> 

js:

var allcheckbox = $("[id^='data']") var count_checked = allcheckbox.filter(":checked").length;  if (count_checked == 0)  {     alert("all check boxes not checked"); } else if(count_checked != allcheckbox.length) {     alert("some of check boxs not checked"); } else{          return confirm("are sure want close these packet?"); } 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -