Checkboxes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
<script src="http://code.jquery.com/jquery-1.9.1.js"></script> <form name="form1"> <div> <label for="checkbox">Checkbox:</label> <input type="checkbox" name="one" id="checkbox" /> </div> <div> <label for="checkbox">Checkbox:</label> <input type="checkbox" name="two" id="checkbox" /> </div> <div> <label for="checkbox">Checkbox:</label> <input type="checkbox" name="three" id="checkbox" /> </div> <div> <label for="checkbox">Checkbox:</label> <input type="checkbox" name="four" id="checkbox" /> </div> <div> <input type="button" value="Submit" class="submitnow"/> </div> </form> <script> $(".submitnow").click(function(){ var chkd = document.form1.one.checked || document.form1.two.checked|| document.form1.three.checked|| document.form1.four.checked; if (chkd) { alert ("Well done"); } else { alert ("Please check a checkbox"); return false; //Prevent it from being submitted } }); </script> |