Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Checkbox validation using javascript

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 576
    Comment on it

    Hello Readers

    We all must have filled some or the other type of a form online. A form for subscription, for a job, an application etc. A form may ask general information of you as your address, name dob, mother tongue etc, or your educational qualifications, work experience, curricular activities etc, depending upon the form you are dealing with. Irrespective of the type of form, one common thing in all of them is Checkbox Validation.

    What exactly is Checkbox Validation?

    When all the entries in the form have been filled, there is a Terms and Condition column at the very bottom of the page with a checkbox. Once you tick the checkbox, only then the form is considered completed. Along with the terms and conditions, there is an important line stating that the user is responsible for the entries filled by him, whether correct or incorrect. THis exactly is checkbox validation. Thus, a genuine user will validate his entries by himself before checking the checkbox to avoid any risks in future.

     

    JavaScript

    <script type="text/javascript">
      function checkForm(form)
      {
        if(!form.terms.checked) {
          alert("Please indicate that you accept the Terms and Conditions");
          form.terms.focus();
          return false;
        }
            return true;
      }
    </script>

     

    HTML:

    <form onsubmit="return checkForm(this);">
        <p><input type="checkbox" name="terms"> I accept the Terms and Conditions</p>
        <p><input type="submit"></p>
    </form>
    

     

    Above code display the following output:

    Above code confirms your entries before submitting the form. If checkbox is checked, you will proceed to the next step. If it’s not checked, an alert message is displayed stating that the checkbox is not marked (you accept the terms and conditions) and focus is moved to the checkbox.

     

    Following output will show if checkbox is not checked:

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: