...

View Full Version : Radio Button Values



philiprakusen
03-15-2005, 01:44 PM
I have two radio buttons in a form...

<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:

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?

codegoboom
03-15-2005, 02:16 PM
How about giving that radio an id, such as id="cc", and then check its state: if(document.getElementById("cc").checked) //validate...

philiprakusen
03-15-2005, 02:21 PM
How about giving that radio an id, such as id="cc", and then check its state: if(document.getElementById("cc").checked) //validate...

Perfect!

Cheers...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum