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