Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Quiz score calculating problem

    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.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    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
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •