...

View Full Version : dropdown menu quiz



lmk
03-03-2005, 10: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 :)



<html>
<head>
<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"
}
}

</script>
</head>

<body>
<form>
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>
</select>
<br /><br />
<select name="myList1">
<option value = "4">Answer 0</option>
<option value = "5">Answer 1</option>
<option value = "6">Answer 2</option>
</select>

<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"
onClick="put()">

</form>
</body>

</html>

Vladdy
03-04-2005, 02:59 AM
You may want to consider this instead of reinventing the wheel:
www.klproductions.com/klquiz.html

lmk
03-04-2005, 08: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 :)

Vladdy
03-05-2005, 02:01 AM
Here is a little demo for you that I threw together. :thumbsup:
http://webdeveloper.klproductions.com/demos/arrangetextquizdemo.html



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum