Checkbox validation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neogazz
    New Member
    • Apr 2010
    • 55

    Checkbox validation

    Dear Bytes Team

    How would you use JavaScript function validation to check wether or not a checkbox is checked or not?

    I am able to check input fields, however I am not sure about checkboxes.

    Regards
    Gary Wilson
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    It it simple, Just have a id attribute in the checkbox. And then use the DOM object for checking.

    ex:
    HTML
    Code:
    <input type="checkbox" id="testObj" checked="checked"/>
    JS
    Code:
    if(document.getElementById('testObj').checked==true)
      alert("Check box checked");
    else
      alert("Check box Not checked");
    Thanks and Regards
    Ramanan Kalirajan

    Comment

    • neogazz
      New Member
      • Apr 2010
      • 55

      #3
      Great this is excellent!

      Comment

      • neogazz
        New Member
        • Apr 2010
        • 55

        #4
        Originally posted by RamananKaliraja n
        It it simple, Just have a id attribute in the checkbox. And then use the DOM object for checking.

        ex:
        HTML
        Code:
        <input type="checkbox" id="testObj" checked="checked"/>
        JS
        Code:
        if(document.getElementById('testObj').checked==true)
          alert("Check box checked");
        else
          alert("Check box Not checked");
        Thanks and Regards
        Ramanan Kalirajan
        Many thanks, this works :)

        Comment

        Working...