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

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:


<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;




<body bgcolor="red">

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

<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

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


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)" />

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.


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

lol j/k :D