midhusrt
03-21-2005, 07:53 AM
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()" />
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()" />