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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Validating a quiz with radio buttons

    Hi,

    I'm new to this game but have a quick question that should be easy for you guys (i hope).

    I'm doing an online quiz this and I am using radio buttons to allow the user to select their answer. Now all i need to know is how to use the selected radio box in an if statement.

    Here is my code and i have set the variables and then used them in the function.
    But when I call the function it just doesnt work. Any ideas?

    I want the user to select an option then click on a button to see if they are correct. The outcome appears in a window.alert


    Thanks for your help

    <script type="text/javascript">
    function check1(){

    chose = document.questions.googol.selectedIndex;
    googolZero = parseInt(document.questions.googol.options[chose].value);


    if (googolZero!="100") {window.alert("Sorry you are wrong, the answer is there are 100 Zero's in a Googol")}

    else {window.alert("Well Done, the answer is 100 zero's in a Googol ");}
    return;
    };
    </script>
    <form name = "questions">
    <label for="question">How many zeros are there in a googol?</label>
    <select name = "google" size= "3"/>
    <option selected="selected" value ="10"> 10</option>
    <option value ="100"> 100</option>
    <option value ="1000"> 1000</option>
    </select>
    <input type="button" value="Check" onclick="check1()" />

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,074
    Thanks
    0
    Thanked 256 Times in 252 Posts
    I thought you were using radio buttons?
    Anyway, the reason it didn't work is because you referenced the select box incorrectly.

    document.questions.googol
    ...
    <select name = "google" size= "3"/>
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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