Click to See Complete Forum and Search --> : Simple checkbox quiz


jolomero
09-12-2003, 07:00 PM
Hi there, I am relatively new at, and struggling to learn, javascripting. :confused:

I am looking for a simple checkbox quiz (yes/no) which also calculates the cumulative values of the 'yes' option (assuming I give the 'yes' option a value of "2".) and then gives a total at the bottom for the cumulated value of the test.

Can anyone point me to a simple sample that I can modify, and hereby learn a bit more about actual javascripting. I tend to learn better by 'doing' than 'reading about'.

Many thanks for your help.

Mr J
09-13-2003, 01:36 PM
Please try the follwoing



<script>
function chk(){
total=0
for(i=0;i<document.f1.length;i++){
if(document.f1.elements[i].type=="radio"&&document.f1.elements[i].checked==true){
total+=document.f1.elements[i].value*1
}
}
document.getElementById("display").innerHTML="Your total score = "+total
}
</script>

<form name="f1">
No Yes<br>
<input type="radio" name="r1" value="0">
<input type="radio" name="r1" value="2"><BR>
<input type="radio" name="r2" value="0">
<input type="radio" name="r2" value="2"><BR>
<input type="radio" name="r3" value="0">
<input type="radio" name="r3" value="2"><BR>
<input type="radio" name="r4" value="0">
<input type="radio" name="r4" value="2"><BR>
<input type="radio" name="r5" value="0">
<input type="radio" name="r5" value="2">

<P><input type="reset"> <input type="button" value="Check" onclick="chk()">
</form>

<div id="display"></div">

jolomero
09-15-2003, 04:46 PM
Thanks for the reply; work has kept me away from both the forum and from giving this a try, but I will do so in the next couple of days.

In the meantime, thanks for the input.

:)

Mr J
09-15-2003, 05:09 PM
If you require a more functional script I have one here

www.huntingground.freeserve.co.uk/scripts/f_whichradm.htm

96turnerri
09-15-2003, 05:23 PM
i was after a quiz this is nice and simple cheers Mr J