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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question I need to Tally the results after a quiz is taken

    This the script I am using,

    <div dir="ltr" style="text-align: left;" trbidi="on">
    <br /></div>
    <!-- begin quiz script -->
    <script>
    function finish() {
    var ext = '.html';
    var results = new Array("none","x","xx");
    var nums = new Array(3);
    for(var i = 0; i < nums.length; i++) nums[i] = 0;
    for(var i = 1; i <= 2; i++) {
    var q = document.forms['quiz'].elements['question_'+i];
    if(q[0].type=='checkbox') {
    var n = 0;
    }
    for(var j = 0; j < q.length; j++) {
    if(q[j].checked) {
    var a = q[j].value.split(',');
    for(var k = 0; k < a.length; k++) {
    nums[a[k]]++;
    }
    if(q[j].type=='radio') break;
    else n++;
    }
    if(j == q.length-1&&q[j].type=='radio') {nums[0]++;}
    }
    if(q[0].type=='checkbox'&&((document.forms['quiz'].elements['question_'+i+'_min']&&n<document.forms['quiz'].elements['question_'+i+'_min'].value)||(document.forms['quiz'].elements['question_'+i+'_max']&&n>document.forms['quiz'].elements['question_'+i+'_max'].value))) nums[0]++;
    }
    var j = new Array('0');
    for (i in nums) if(nums[i]>nums[j[0]]){j=new Array(''+i);} else if(nums[i]==nums[j[0]])j[j.length] = i;
    //var o = '';for(var i in results)o+=results[i]+'='+nums[i]+'\n';
    //alert(o);
    if(nums[0]!=0) {
    alert('You missed or incorrectly answered '+nums[0]+' questions!');
    }
    else if(j[0]==0) {
    alert('No result could be determined.');
    }
    else {
    location = results[j[0]]+ext;
    }
    }
    </script>
    <!-- end quiz script -->



    <!-- begin quiz html -->
    <form name="quiz" action="javascript:finish();">
    <table width="100%" border="0" cellspacing="0" cellpadding="5">
    <tr>
    <td width="34%">
    <font size="2" face="Verdana, Arial, Helvetica, sans-serif">
    <strong>a</strong>
    </font>
    </td>
    </tr>
    <tr>
    <td>
    <font size="2" face="Verdana, Arial, Helvetica, sans-serif">
    <input name="question_1" type="radio" value="1" /> o
    </font>
    </td>
    </tr><tr>
    <td>
    <font size="2" face="Verdana, Arial, Helvetica, sans-serif">
    <input name="question_1" type="radio" value="2" /> f
    </font>
    </td>
    </tr>
    </table>
    <br /><table width="100%" border="0" cellspacing="0" cellpadding="5">
    <tr>
    <td width="34%">
    <font size="2" face="Verdana, Arial, Helvetica, sans-serif">
    <strong>a</strong>
    </font>
    </td>
    </tr>
    <tr>
    <td>
    <font size="2" face="Verdana, Arial, Helvetica, sans-serif">
    <input name="question_2" type="radio" value="1" /> a
    </font>
    </td>
    </tr><tr>
    <td>
    <font size="2" face="Verdana, Arial, Helvetica, sans-serif">
    <input name="question_2" type="radio" value="2" /> j
    </font>
    </td>
    </tr>
    </table>
    <br /> <input type="submit" value="Finish" />
    <input type="reset" value="Reset" />
    </form>
    <!-- end quiz html -->


    I would like a Private tally board of the total sum of what results where picked,

    *I need to see what results where suggested*

    *Kind of live a voting script, Where Result (a) 10+ & Result be 5+*

    I need it to be implemented with this html because this was the only proper quizzing software I've found.

    All suggestions are appreciated.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,220
    Thanks
    23
    Thanked 606 Times in 605 Posts
    Peyt is there a reason why you want to do this in javascript? I ask because to get the correct answer you have to have it store(so to speak) in the html file and anyone with a little knowledge can read them and get 100%. This is better to do in a server side language.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,349
    Thanks
    11
    Thanked 589 Times in 570 Posts
    Quote Originally Posted by sunfighter View Post
    Peyt is there a reason why you want to do this in javascript? I ask because to get the correct answer you have to have it store(so to speak) in the html file and anyone with a little knowledge can read them and get 100%..
    i disagree. i just looked at it for 5 mins and it's so blocky and repetitive that i have no idea where the answers come from.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%


  •  

    Tags for this Thread

    Posting Permissions

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