...

View Full Version : SELECT name of FORM undefined! Why? Please help



qball
06-10-2004, 02:15 AM
Could someone please help me with this seemingly simple problem. Ok...here is the deal. I am try to make a trivia quiz problem that will allow the users to enter the number of questions they want to try and the time limit. When these options are selected, then can click on the 'Start Quiz' button and take the quiz.

I named my SELECT 'xxx' and 'yyy' for simplicty sake. My form name is simply just 'formA'. My problem lies in that fact that I can't seem to get the value the user selected. I need these value to pass to my function. But everytime I try, I keep getting the message "xxx (or yyy) undefined". I don't understand why that is. Could you look at my code and give my any feedback what I am doing wrong. Why is it undefined? This is suppose to be simple but somehow the program is not responding. Oh my God ,if anyone can help, I will appreciate it so much. sigh....here is my code:




<html>

<head>
<title>Online Quiz</title>

<script language="javascript">
function start_quiz()
{
var p1=document.formA.xxx.options[xxx.selectedIndex].value;
var p2=document.formA.yyy.options[yyy.selectedIndex].value;

parent.top_frame.global_frame.reset_quiz(p1,p2);
window.location.href="askQuestions.html";
}

</script>

</head>


<body bgcolor="red">


<form name="formA">
Number of Questions
<br>
<SELECT name="xxx" size="1">
<option value=1>1
<option value=3>3
<option value=5>5
</SELECT>

<br><br>Time Limit<br>
<SELECT name="yyy" size="1">
<option value=-1>No Limit
<option value=60>1 Minutes
<option value=120>2 Minutes
<option value=180>3 Minutes
</SELECT>

<br>
<input type="button" value="start quiz" language="javascript" onclick="return start_quiz()">
</form>



</body>
</html>

glenngv
06-10-2004, 04:56 AM
You refer to the select properly in the first instance but incorrectly in the next.

var p1=document.formA.xxx.options[document.formA.xxx.selectedIndex].value;
var p2=document.formA.yyy.options[document.formA.yyy.selectedIndex].value;

You can pass the form reference to the function to simplify it.

function start_quiz(f)
{
var p1=f.xxx.options[f.xxx.selectedIndex].value;
var p2=f.yyy.options[f.yyy.selectedIndex].value;
...

<input type="button" onclick="return start_quiz(this.form)" />

qball
06-10-2004, 08:08 PM
Oh my God...Glenngv, you are so right on! That solves everything. Thank you so much for helping me.

qball

Borommakot
06-10-2004, 08:20 PM
DANGIT! finally something i KNOW and someone gets there before me :(


lol j/k :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum