check tick box is ticked...

Discussion in 'JavaScript' started by red_fiesta, Jun 6, 2007.

  1. #1
    I need to see if a check box is ticked

    at the moment i am using the code.

    ..

    		
    
    else if (document.callback.terms.value <= "")
        {
          alert ("You must accept the terms and conditions");
          return false;
        }
    
    
    Code (markup):
    but this isnt working. Please advise.

    Thanks
     
    red_fiesta, Jun 6, 2007 IP
  2. Mike H.

    Mike H. Peon

    Messages:
    219
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You shouldn't have a checkbox outside of a form.

    <form action="">
    <input type="checkbox" name="agree">
    </form>
    
    
    if (document.forms[0]['agree'].checked)
            {
                //do something
            }
    else   {
               // do something else
            }
    Code (markup):
     
    Mike H., Jun 6, 2007 IP
  3. blefleur

    blefleur Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    See my code below. This will get you what you want:
    <script type="text/JavaScript">
    <!--
    function waterbrook()
    {
    if (document.trotwood.steerforth.value !="James" && document.trotwood.steerforth.value != "james")
    {
    alert ("Error. Try again.");
    return false;
    }
    if (document.trotwood.steerforth.value == "")
    {
    alert ("Error. Try again.");
    return false;
    }
    if (document.trotwood.wickfield.checked == false)
    {
    alert ("Check the box, please!");
    return false;
    }
    return true;
    }
    // -->
    </script>
     
    blefleur, Jun 12, 2007 IP