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 Coder
    Join Date
    Sep 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 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
    Senior Coder
    Join Date
    Feb 2006
    Location
    USA
    Posts
    1,013
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #3
    New Coder
    Join Date
    Sep 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    't works! Thanks!


  •  

    Posting Permissions

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