...

View Full Version : online quizzes



itsonlybarney
05-10-2004, 10:27 AM
is there a way of using java script to add up the score of a quiz with the different answers meaning different scroes. below is a sample question. there are 6 questions per page.

<b>1.</b>Your boss dangles a promotion in front of you with the promise that you’ll be given “more responsibility”. You…
<br><input type="radio" name="_Q486" value=0>Ask if this means that Friday night drinks, er, work functions, can now be claimed back on expenses. And does this apply to the rest of the week as well?
<br><input type="radio" name="_Q486" value=1>Find out what the responsibilities are and feel relieved that you’ll be able to pay off you credit card debt with the pay rise.
<br><input type="radio" name="_Q486" value=2>Noticeably perk up. You tell your boss as the eldest child, you’ve dealt with siblings and are capable of handling this promotion. Follow up with a gushing thank-you note, written on gold-embossed, personalised stationary.
<br>

any help would be appreciated, thnx.

homerUK
05-10-2004, 11:48 AM
I think you would just have a function where it would get the value of each radio button, then simply add it all up....?

- not got time to write one now - but will once I get back!

Vladdy
05-10-2004, 12:31 PM
www.klproductions.com/klquiz.html

itsonlybarney
05-12-2004, 03:55 AM
Below is some of the code on my site. It uses VBScript and I was wondering if anyone would be able to convert it to something similar in JavaScript to make it accessible to all internet browsers rather that IE.


<script Language="VBScript" type="text/VBScript">
<!--
SUB sum_scores()

score = CSng(AreUStillAKid.Q1.value) + CSng(AreUStillAKid.Q2.value) + CSng(AreUStillAKid.Q3.value) + CSng(AreUStillAKid.Q4.value) + CSng(AreUStillAKid.Q5.value) + CSng(AreUStillAKid.Q6.value)

AreUStillAKid.scoreOutput.value=score

END SUB
-->
</script>

I have a hidden input for each question so that i can store the value and there are 6 questions on this page.

<input type="hidden" name="Q1" value=0>

This is the question and each click on the radio button sets the value of the above hidden input.

<tr><td colspan=2><font color=yellow><b>1.</b>Your boss dangles a promotion in front of you with the promise that you’ll be given “more responsibility”. You…</font></td></tr>
<tr><td><input type="radio" name="1" value=0 onClick=AreUStillAKid.Q1.value=0></td><td><font color=white>Ask if this means that Friday night drinks, er, work functions, can now be claimed back on expenses. And does this apply to the rest of the week as well?</font></td></tr>
<tr><td><input type="radio" name="1" value=1 onClick=AreUStillAKid.Q1.value=1></td><td><font color=white>Find out what the responsibilities are and feel relieved that you’ll be able to pay off you credit card debt with the pay rise.</font></td></tr>
<tr><td><input type="radio" name="1" value=2 onClick=AreUStillAKid.Q1.value=2></td><td><font color=white>Noticeably perk up. You tell your boss as the eldest child, you’ve dealt with siblings and are capable of handling this promotion. Follow up with a gushing thank-you note, written on gold-embossed, personalised stationary.</font></td></tr>
<tr><td colspan=2>&nbsp</td></tr>

This is the last bit of the code which calls the script to add up the score.

<tr><td colspan=2><input type="button" value="Submit" onClick="sum_scores()"></td></tr>
<tr><td colspan=2><font color=white><b>Your score: </b></font><input type="text" name="scoreOutput" value=0 size=4></td></tr>

If you can help it would be greatly appreciated.

Itsonlybarney

itsonlybarney
05-13-2004, 03:15 AM
can anyone convert the above VBScript into Javascript?

glenngv
05-13-2004, 04:53 AM
There are better ways to implement your script without using a hidden field for each question, but I'm lazy to code it. :p :D
So I just convert the sum_scores function to javascript.


<script type="text/javascript">
function sum_scores(){
var f = document.AreUStillAKid;
var score = 0;
for (var i=1;i<=6;i++){
score += parseInt(f.elements['Q'+i].value,10);
}
f.scoreOutput.value=score;
}
</script>

itsonlybarney
05-13-2004, 11:18 AM
thanks for the sum_scores() help. can anyhelp me get the data from the questions and store it in an array so that i dont have to use the hidden fields?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum