...

View Full Version : Quiz score calculating problem



kaye9
07-29-2008, 11:06 AM
I've got a "quiz" (a test really) of about 20 questions, each question has a set of 5 radio buttons (your opinion from 'fully disagree to fully agree', you could say) with which you get points from 1 to 5. Submitting the form takes you to an invisible results page which redirects to one of three actual Results pages which the user will see, according to the total score from the form.

In theory anyway...My problem is, there's something wrong with my calculate function because I can't seem to get the form to return the total score, I get a zero (0).

In detail:...

The form is called 'test'.
For each answer I've got a hidden field next to it called 'score1', 'score2' etc. And a hidden field for the total score called 'total_score'.
For the radio buttons I use the following (this is option 1 for question 1):

<input type="radio" name="q1" id="q1-1" value="1" onclick="this.form.score1.value=1;calculate();"

The actual 'calculate' function is as follows:

function calculate() {
var p1, p2, p3...20;
var fullscore;
p1 = test.score1.value * 1;
p2 = test.score2.value * 1;
p3 = test.score3.value * 1; etc
fullscore = p1 + p2 + p3 etc... p20;
test.total_score.value = fullscore

On the form submit button i call "return GiveScore()";, and that function is like this:

function GiveScore() {
var fscore;
fscore = test.total_score.value
return true;

}

...

And that's about it. But as said, it doesn't work and it returns a zero (0) instead of the calculated score. I've also tried leaving the initial values for the variables empty, or using 0 or 1.

abduraooft
07-29-2008, 11:33 AM
Post complete code of your document(html+javascript). BTW please read http://www.codingforums.com/showthread.php?t=82672 on how to post your code in this forum.

PS: Welcome to Codingforums :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum