Sync files across computers for FREE click here for your free account



If you would like to show a javascript alert if no checkbox was checked in a form, you need to validate the checked property of that checkbox. By using the onSubmit event of the form and a JS function similar to the example below you can validate your form correctly.

1

2

3

 

 

Example code
<SCRIPT TYPE="text/javascript" LANGUAGE=JAVASCRIPT>
<!--
//------------------------------------------/
// Code from http://www.NetEvolution.co.uk
//------------------------------------------/
function checkCheckBoxes() {
if (document.frmTest.CHKBOX_1.checked == false &&
document.frmTest.CHKBOX_2.checked == false &&
document.frmTest.CHKBOX_3.checked == false)
{
alert ('You didn\'t choose any of the checkboxes!');
return false;
}
else
{
return true;
}
}
//-->
</SCRIPT>


<form onsubmit="return checkCheckBoxes();" action="">
<input type="checkbox" name="CHKBOX_1" value="1">1</p>
<input type="checkbox" name="CHKBOX_2" value="2">2</p>
<input type="checkbox" name="CHKBOX_3" value="3">3</p>
<input type="submit" value="Submit!" />
</form>



No mentions on Twitter yet. (Be the first to Tweet this post)

Host your site with EUKHost and Save 10%, use coupon 10%NEW, Dedicated, VPS, Shared, Linux, Windows, Reseller - save money on web hosting with our web hosting coupons.

Similar articles on NetEvolution.co.uk