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

Thread: Scored Survey

  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Scored Survey

    Hi

    I'm trying to create a scored survey for a website - along the lines of 'How many of the following countries have you been to?'. From there the user can click as many as he wants (each worth one point) and there are multiple results depending on how many options the user has selected.

    Can anyone show me a template for a survey like this, or give me some pointers as to how to create one. I'm especially having difficulty with the multiple answers, so if anyone could help that would be great.

    On a side note I also want the results to be shared via Facebook, eg 'user has been to 43 out of 50 countries', and I have tried the dialogues on Facebook developers but have had limited success.

    Thanks a lot

    Alex

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,243
    Thanks
    203
    Thanked 2,555 Times in 2,533 Posts
    Suggest you have a checkbox for each listed country, then add up the total checked, use a switch statement to determine which message is displayed.

    I don't understand what you mean by "multiple answers". Do you mean that there are multiple results messages depending on the score?

    This ought to move you forward. You could assign differnt "points" values to different countries if you wish. So Germany counts 1 but Australia counts 3. Or whatever.


    Code:
    <html>
    <head>
    
    <style = "text/css">
    body {font-family:arial; font-weight:bold;}
    </style>
    </head>
    <body>
    
    <form id = "myform">
    USA <input type = "checkbox" name= "chk1" value = "1" >
    Germany <input type = "checkbox" name= "chk1" value = "1">
    France <input type = "checkbox" name= "chk1" value = "1" >
    Australia <input type = "checkbox" name= "chk1" value = "1" >
    Japan <input type = "checkbox" name= "chk1" value = "1" >
    
    <input type = "button" value = "Get Total" onclick = "addemup()">
    </form>
    
    <script type = "text/javascript">
    
    function addemup() {
    var total = 0;
    var count = 0;
    var f = document.getElementById("myform");
    for (var i=0; i<f.chk1.length; i++) {
    if (f.chk1[i].checked==true) {
    total = total + (f.chk1[i].value*1);
    count++;
    }
    }
    
    if (count == 1) {
    alert ("The value of the checkbox you have checked is " + total);
    }
    else if (count>1) {
    alert ("The total of the " + count + " checkboxes you have checked is " + total);
    }
    }
    
    // then display a message depending on the value of total.  Example:-
    if ((total > 0) && (total <4)) {
    var message = ("You have not travelled much.");
    }
    
    </script>
    
    </body>
    </html>
    Can't help you with Facebook.


    "... liberalism, with a small 'c'....." - David Blunkett MP, Today Programme.
    Last edited by Philip M; 11-05-2012 at 05:56 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    AlexCrow (11-05-2012)

  • #3
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Hi thanks for your suggestions.

    By multiple answers, I mean depending on how many boxes you check you go to a different results page which gives you your score and a description eg:

    0-10 checks = Bad
    10-20 checks = OK
    20-30 checks = Good
    etc.

    Would this be possible with a switch statement??

    Thanks

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,243
    Thanks
    203
    Thanked 2,555 Times in 2,533 Posts
    Quote Originally Posted by AlexCrow View Post
    Hi thanks for your suggestions.

    By multiple answers, I mean depending on how many boxes you check you go to a different results page which gives you your score and a description eg:

    0-10 checks = Bad
    10-20 checks = OK
    20-30 checks = Good
    etc.

    Would this be possible with a switch statement??

    Thanks

    Yes, it would. But probably simpler just with a series of if/else statements as there are only a few outcomes. See my suggested code above.
    Last edited by Philip M; 11-05-2012 at 06:01 PM. Reason: Typo

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts
    One more quick question.

    How would I open the results page in a separate tab but obviously link the results to the original checklist page?

    Cheers

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,243
    Thanks
    203
    Thanked 2,555 Times in 2,533 Posts
    Quote Originally Posted by AlexCrow View Post
    One more quick question.

    How would I open the results page in a separate tab but obviously link the results to the original checklist page?

    Cheers
    Not sure what you mean. Only the user can decide whether to open a page in a new window, the same window or a tab.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #7
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts
    My bad, I meant to say a new page not tab.

    Instead of the score being a pop up alert, do I just make the 'submit my score' button a link which brings the user to a new page with the results on?

    If not how do I get it to come through on a new page?

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,243
    Thanks
    203
    Thanked 2,555 Times in 2,533 Posts
    You will need to pass the value of the score to a new page using a query string.

    For more info see

    http://javascript.about.com/library/blqs.htm

    Another way would be to use a cookie.
    Last edited by Philip M; 11-05-2012 at 06:28 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    AlexCrow (11-06-2012)


  •  

    Posting Permissions

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