Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2004
    Location
    London
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Radio Button Values

    I have two radio buttons in a form...
    Code:
    <input type="radio" name="payment_method" value="account">
    <input type="radio" name="payment_method" value="credit_card">
    ...and some IF statements in a validation function:
    Code:
    if (document.payment_details.payment_method.value == 'credit_card') {
      //Check that the credit card name has been entered
      if (document.payment_details.credit_card_name.value == '') {
        alert ('Please enter the name as it appears on your credit card.');
        return false;
      }
    
      //Do some other stuff
      ...
      ...
    
    }
    The problem I having is getting the IF statements to run only if the credit card button is checked, i.e. skip the validation if the user has clicked ACCOUNT.

    Basically, with the above script, the statements never run.

    Any ideas would be appreciated?

  • #2
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How about giving that radio an id, such as id="cc", and then check its state: if(document.getElementById("cc").checked) //validate...
    *this message will self destruct in n-seconds*

  • #3
    New to the CF scene
    Join Date
    Dec 2004
    Location
    London
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by codegoboom
    How about giving that radio an id, such as id="cc", and then check its state: if(document.getElementById("cc").checked) //validate...
    Perfect!

    Cheers...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •