...

View Full Version : Scored Survey



AlexCrow
11-05-2012, 01:26 PM
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

Philip M
11-05-2012, 05:48 PM
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.



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

AlexCrow
11-05-2012, 05:53 PM
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

Philip M
11-05-2012, 05:57 PM
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.

AlexCrow
11-05-2012, 06:07 PM
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

Philip M
11-05-2012, 06:10 PM
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.

AlexCrow
11-05-2012, 06:13 PM
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?

Philip M
11-05-2012, 06:18 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum