View Full Version : Questionnaire Help

07-24-2012, 11:59 AM
Hi Guys,
I wonder if anyone could help me? I am making a retail site and I need to make some sort of questionnaire to direct customers to the correct type of product.
I have five multiple choice questions and I want to assign a value to each answer, total it all at the end and show a few products that would suit... I'm quite new to JS and I don't know if this is even possible.
To make it slightly more confusing I would like question two to only be shown if a certain answer is given to question one.
I would really appreciate some help.
Thank you

Philip M
07-24-2012, 12:01 PM
This forum is not a free coding service. As a general rule, the people helping out in this forum don't write code for others (especially code that appears to be for a commercial application), but try to help with fixing code that doesn't work. You may perhaps get someone to write this script for you, but you'll be far more likely to get help if you have made a substantial effort and written some code yourself. Then someone here will almost certainly help you correct/improve your work.

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

07-24-2012, 12:07 PM
I wasn't asking for anyone to code for me, I want to know if this is possible and to maybe point me in the right direction... I have spent a good few hours on it and I didn't want to waste anymore time if it’s something that is never going to work.

Thanks anyway...

Philip M
07-24-2012, 04:35 PM
Of course it is possible, (but perhaps not achieveable for you at this stage if you don't have much knowledge of Javascript) but your requirement is too vague and ill-defined to do much with. What does "some sort of questionaire" mean?

Here is code to add up the scores of sets of radio buttons:-


<form name= "myform">
Choose one from this group<br>
RED <input type = "radio" name = "rad1" value = "0" >
BLUE <input type = "radio" name = "rad1" value = "1" >
GREEN <input type = "radio" name = "rad1" value = "2" >
YELLOW <input type = "radio" name = "rad1" value = "3">
BROWN <input type = "radio" name = "rad1" value = "4">
And one from this group<br>
PINK<input type = "radio" name = "rad2" value = "0" >
PURPLE<input type = "radio" name = "rad2" value = "1" >
GREY<input type = "radio" name = "rad2" value = "2" >
BLACK<input type = "radio" name = "rad2" value = "3" >
WHITE <input type = "radio" name = "rad2" value = "4">


<input type = "button" value = "Calculate Score" onclick ="calc()">

<script type = "text/javascript">

var numOfGroups = 2;

function calc() {

var score = 0;

for (var j =1; j<=numOfGroups; j++) {
var f = document["myform"]["rad"+j];
for (var i=0; i<f.length; i++) {
if (f[i].checked) {
score += Number(f[i].value);
alert ("You scored " + score);



Is that the sort of thing you want?

Have you thought this through? Suppose a user scores 1 + 5 + 14 total 20, that is the same result total as scores of 14 + 1 + 5 - very different answers.

Why not simply use a select box where the user can choose the type of product he is interested in?

As this is a commercial site I suggest you do what you would expect to do in any other field when you wanted technical expertise - hire a professional.