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 7 of 7

Thread: online quizzes

  1. #1
    Regular Coder
    Join Date
    May 2004
    Location
    Sydney, Australia
    Posts
    281
    Thanks
    0
    Thanked 0 Times in 0 Posts

    online quizzes

    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.

  • #2
    Regular Coder
    Join Date
    Nov 2002
    Location
    Manchester, UK
    Posts
    533
    Thanks
    4
    Thanked 1 Time in 1 Post
    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!

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

  • #4
    Regular Coder
    Join Date
    May 2004
    Location
    Sydney, Australia
    Posts
    281
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    Code:
    <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.
    Code:
    <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.
    Code:
    <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.
    Code:
    <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

  • #5
    Regular Coder
    Join Date
    May 2004
    Location
    Sydney, Australia
    Posts
    281
    Thanks
    0
    Thanked 0 Times in 0 Posts
    can anyone convert the above VBScript into Javascript?

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    There are better ways to implement your script without using a hidden field for each question, but I'm lazy to code it.
    So I just convert the sum_scores function to javascript.
    Code:
    <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>

  • #7
    Regular Coder
    Join Date
    May 2004
    Location
    Sydney, Australia
    Posts
    281
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?


  •  

    Posting Permissions

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