html - Javascript Checkbox Validation not Checking if Ticked -
i've looked through lot of questions people have asked on this, cannot find solution has helped me.
i'm beginner programming know little do, have 4 check boxes , submit form, have select @ least 1 of them, no message comes , form able submitted without 1 of boxes being ticked.
this code below:
<tr> <td align="right"> <label for="erdbeersocken"><p>erdbeersocken<sup>*</sup>:</label> <br> <label for="armstulpen">armstulpen<sup>*</sup>:</label> <br> <label for="cupcakes">cupcakes<sup>*</sup>:</label> <br> <label for="babykleidung">babykleidung<sup>*</sup>:</label> <br> </td> <td align="left"> <form action="../" onsubmit="return checkcheckboxes(this);"> <input type="checkbox" name="checkbox_1" value="erdbeersocken"> <br> <input type="checkbox" name="checkbox_2" value="armstulpen"> <br> <input type="checkbox" name="checkbox_3" value="cupcakes"> <br> <input type="checkbox" name="checkbox_4" value="babykleidung"> <br> <input type="submit" value="submit!"> </td> </tr> </form> <script type="text/javascript" language="javascript"> <!-- function checkcheckboxes(theform) { if ( theform.checkbox_1.checked == false or theform.checkbox_2.checked == false or theform.checkbox_3.checked == false or theform.checkbox_4.checked == false) { alert ('you didn\'t choose of checkboxes!'); return false; } else { return true; } } //--> </script> which looks like: text here (checkbox here)
i'm using notepadd++ more advanced code not seem work, if me simplified javascript, appreciate it. :)
function checkcheckboxes(theform) { if ($("input[type='checkbox']:checked").length){ return true; }else{ alert ('you didn\'t choose of checkboxes!'); return false; } }
Comments
Post a Comment