View Full Version : dropdown menu quiz

03-03-2005, 11:36 PM
hi all, I am very new to Javascript and trying to create a javascript quiz which students are answering them by choosing the answers from a dropdown menu, the dropdown menu are created by arrays, so they have common name like QS0, QS1...and so on.

When I tried to submit the answers to a function for checking, I could not get the values over.I have been successful was a text box contect, but could not be done so with a drop menu.

below are the sample code i am working on now before putting in the actual questions.


the code works when i make the contect inside the function to read each of the dropdown menu sepearte, but I am trying to make it into an array so I can change the number of questions when required.

many thanks :)

<script type="text/javascript">
function put()
for (i=0;i<2;i++)
txt=eval("document.forms[0].myList" + i + ".options[document.forms[0].myList" + i +.selectedIndex].text")
document.forms[0].answer" + i +".value=txt"


Question 1:
<br /><br />
<select name="myList0">
<option value = "1">Answer A</option>
<option value = "2">Answer B</option>
<option value = "3">Answer C</option>
<br /><br />
<select name="myList1">
<option value = "4">Answer 0</option>
<option value = "5">Answer 1</option>
<option value = "6">Answer 2</option>

<br /><br />
Your answer 1 is: <input type="text" name="answer0" size="20">
<br /><br />
Your Answer 2 is: <input type="text" name="answer1" size="20">
<br /><br />
<input type="button" name="button1"
value="Display answers"



03-04-2005, 03:59 AM
You may want to consider this instead of reinventing the wheel:

03-04-2005, 09:52 AM
thank you for your help, but actually current design (not a very gd coding) is having a passage paragraph randomise (I have successed in this) and use a dropdown menu to allow student to choose the correct order of the paragraph.

the problem lies in it now is that I can't pass the dropdown menu (which was created in array mehtod to the function for checking.

my first post where the section was highlighted in red is the part I believe I am having problem with.

thx :)

03-05-2005, 03:01 AM
Here is a little demo for you that I threw together. :thumbsup: