View Full Version : Radio button IF statement

10-13-2006, 11:21 PM

I have a function that calculates a cost, but I want to add a feature that allows users to select whether or not they are a member, in which case they would save $25. I have the yes / no radio buttons built.. but I'm not sure how to test if one is checked and then write the statement.

I tried:

if ( document.reg.member.value = "yes" )
{ cost = (cost + (number*30)) - 25; }
else {cost = cost + (number*30) }

My radio buttons are:
<input type="radio" name="member" value="yes" /> Yes
<input type="radio" name="member" value="no" /> No

Any suggestions?

10-14-2006, 12:25 AM
I'm glad to see you made a stab at it. :)

You need to tell it which element with that name to check and you need to check its checked property, which fill be set to true or false.

if ( document.reg.member[0].checked )

10-14-2006, 12:55 AM
't works! Thanks!