JavaScript Checkbox Validate


This script will check to see if any checkboxes have been checked, and if not, the form will not be submitted.




Checkbox one

Checkbox two

Checkbox three


Script Source


<The Form>

<form action="" onsubmit="return checkCheckBoxes(this);">
<p><input type="CHECKBOX" name="box_1" value="Checkbox one"> Checkbox one</p>
<p><input type="CHECKBOX" name="box_2" value="Checkbox two"> Checkbox two</p>
<p><input type="CHECKBOX" name="box_3" value="Checkbox three"> Checkbox three</p>
<p><input type="SUBMIT" value="Try it!"></p>

<The JavaScript >

<script type="text/javascript" language="JavaScript">
<!-- Hide form old browsers
function checkCheckBoxes(theForm) {
if (
theForm.box_1.checked == false &&
theForm.box_2.checked == false &&
theForm.box_3.checked == false)
alert ('Please choose an option!');
return false;
} else {
return true;
// end -->

Please let me know if this script was helpful to you.