Welcome to W3Courses
 Like Us on Facebook

Validate a Check Box Using JavaScript

Using javaScript it is possible to check whether a check box has been checked or not. This is handy if you need your users to agree to the terms and conditions before they sign up. A check box has a checked property, which returns either a 0 for not checked and a 1 for checked. Following code shows how you can validate the checkboxes.


<!-- hide the script from older browsers
function validateForm(form)
   if(form.termscheck.checked != 1)
   {   alert('Please acknowledge that you agree to the Terms and Conditions.');
       return false; 
       return true;
// end hiding-->

<FORM onsubmit='return validateForm(this)' action='http://www.w3courses.com/index.php' method=post>
<P align=center><INPUT type=checkbox value=yes name=termscheck> I agree to the Terms and Conditions</P>
<P align=center><INPUT type=submit value='SIGN UP' name=submit></P>