Checking Check Box.

Discussion in 'JavaScript' started by kolucoms6, Feb 5, 2011.

  1. #1
    I have a Page as http://tinyurl.com/4uk7esy

    Now what I am looking is When I click on Subscribe Button , it shld check whether box check Boxes are Checked or Not If Not then Don't Proceed.

    Subscribe Button is NOT a Normal Command Button.

    Code for Check Box
    *************************

    Code of Button :
    *************************

     
    kolucoms6, Feb 5, 2011 IP
  2. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Didn't test it, but you could try placing these lines right at the beginning of goPayment Function:

    
    function goPayment()
    {
       var chk_agree = document.getElementById('agree');
       var chk_agree1 = document.getElementById('agree1');
    
       if (!chk_agree.checked || !chk_agree1.checked) return false;
    
      ...
    
    Code (markup):
     
    hogan_h, Feb 5, 2011 IP
  3. kolucoms6

    kolucoms6 Active Member

    Messages:
    1,198
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    75
    #3
    But I get an Error as :

    1) Object Reqd
    2) ; Expected
     
    kolucoms6, Feb 5, 2011 IP
  4. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Again, didn't test the sample, but by looking at your code, this line is wrong:
    
    alert chk_agree.checked;
    
    Code (markup):
    Try leaving it out for testing purposes or rewrite it as:
    
    alert(chk_agree.checked);
    
    Code (markup):
    Seeing as it's only there for debugging purposes, you can leave it out, it would just output "false" anyways.
     
    hogan_h, Feb 5, 2011 IP
  5. srisen2

    srisen2 Peon

    Messages:
    359
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i would do this with onsubmit in a form and try the following. This way the user doesnt see the popup error but the entire form is disabled unless the checkbox is checked.

    document.getElementById('submit').disabled = true;

    if (document.forms["formname"]["agree"].checked = "1")
    {
    document.getElementById('submit').disabled = false;
    }
    else{
    return false;
    }
     
    srisen2, Feb 8, 2011 IP