Web Analytics Made Easy -
StatCounter Radio button IF statement - CodingForum

Announcement

Collapse
No announcement yet.

Radio button IF statement

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Radio button IF statement

    Hello,

    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?

  • #2
    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.
    Code:
    if ( document.reg.member[0].checked )
    Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions
    Java != JavaScript && JScript != JavaScript
    Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.

    Comment


    • #3
      't works! Thanks!

      Comment

      Working...
      X