Closed Thread Icon

Topic awaiting preservation: Javascript: Points based questionnaire (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=8448" title="Pages that link to Topic awaiting preservation: Javascript: Points based questionnaire (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Javascript: Points based questionnaire <span class="small">(Page 1 of 1)</span>\

 
Boudga
Maniac (V) Mad Scientist

From: Jacks raging bile duct....
Insane since: Mar 2000

posted posted 12-24-2002 17:44

I am searching for a (must be a client side solution) javascript that will do the following:

i want to pose several questions, give the user the choice of 1, 2, or 3 using radio buttons and then at the end of the questionnaire all choices will be added to reveal a final score.

Can anyone point me to a javascript that can do this?

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 12-24-2002 17:53

Check out what I'm doing here. This is usually a window that's opened via window.open. It uses two divs and points to show the score and correct answers.

Ultrakapy
Obsessive-Compulsive (I) Inmate

From:
Insane since: Aug 2002

posted posted 12-27-2002 19:44

I don't know of a link to the script you want, but I think all you need to do is loop over the radio buttons, get the value of each checked radio button, add and store this value to a variable each time. After the loop, that variable will contain the sum of the values of the checked radio buttons. If you want I can write up a quick demo later.

Nevel
Bipolar (III) Inmate

From: Amsterdam
Insane since: Jun 2002

posted posted 12-30-2002 13:22

I've written such a script a while ago.
You can take a peek at http://www.blind-justice.nl/games/quizz.htm
or download the script at http://www.blind-justice.nl/games/quizz.js
The score thingy, however, is written in php, so that won't work for you.
But I think it shouldn't be too hard to modify the script.

Boudga
Maniac (V) Mad Scientist

From: Jacks raging bile duct....
Insane since: Mar 2000

posted posted 01-04-2003 15:25

Nevel,

Actually what I need is a multiquestion points based survey. There are no right or wrong answers...

That is pretty close to what I'm trying to achieve. Thanks for posting that! I still have a few problems that perhaps you can help me with.

Problems:
1. I copied quizz.htm and quizz.js to my personal web server (to begin hacking it to fit my needs) and when I ran it there (unaltered) it would not initQuizz. I assume you are parsing something with PHP prior to running initQuizz? Otherwise this should work...right?

2. In your quizz.js you write the score to score.php I would like to simply write it to another layer and I'm not familiar enough with JS to do so with what you've written. Perhaps I could figure it out if I could get it to initialize in the first place.

3. I would like to change the scoring system also. Here are my variables:

Each question will be able to be answered by choosing from radio buttons next to these choices:
1. Never
2. Sometimes
3. Always

Also, in scoring I want 1 to equal 1, 2 to equal 2, and 3 to equal 3 instead of multiplying times 10 as you have it in your quizz.js. At the end of the quizz all will be added for a cumulative score.

I've already changed all the questions in your script to my own and answers I changed to '1, 2, 3,' .

Can you help me tweak the script to make this work?



[This message has been edited by Boudga (edited 01-06-2003).]

Boudga
Maniac (V) Mad Scientist

From: Jacks raging bile duct....
Insane since: Mar 2000

posted posted 01-06-2003 16:23

I could sure use some more help on this....Puhleeeeeese?!?!?

reitsma
Maniac (V) Mad Scientist

From: the bigger bedroom
Insane since: Oct 2000

posted posted 01-07-2003 05:10

ok... let's try and make this as easy as possible - we don't want no hardcoding, do we buddy?

so....

code:
function checkkit() {
score = new Number(0); //start score at zero.
for(i=0;i<document.forms[0].elements.length;i++) { //for every element in the form
if(document.forms[0].elements[i].type=='radio') { //if the element is a radio button
if(document.forms[0].elements[i].checked) { //and the button is checked
score = score + parseInt(document.forms[0].elements[i].value); //add that button's value to the score.
}
}
}
alert(score); //then alert the final score.
} // end function checkkit





that's all the code does. it does not ensure that at least one of each is selected, or anything else.

hope this helps - if it does, you now owe me a pspong return.

[This message has been edited by reitsma (edited 01-07-2003).]

Boudga
Maniac (V) Mad Scientist

From: Jacks raging bile duct....
Insane since: Mar 2000

posted posted 01-09-2003 16:39

Sorry, Adam for the lack of PSPONG return...I'm freelancing fulltime and I just recently got more work than I could possibly handle alone and have been working ungodly hours to keep the client happy...which has meant that I've had to focus solely on getting their stuff done...I apologize profusely!

I've got some time now...I'll come up with a return right now....

reitsma
Maniac (V) Mad Scientist

From: the bigger bedroom
Insane since: Oct 2000

posted posted 01-09-2003 23:41

no sweat bruce - just tell me if that little javascript gem i coded you was useful or not!

Boudga
Maniac (V) Mad Scientist

From: Jacks raging bile duct....
Insane since: Mar 2000

posted posted 01-13-2003 03:16

thanks Adam for the JS gem you came up with...however, I'm JS challenged and unsure how to build on that or incorporate it with other JS to make it work...can you give me a working example?

reitsma
Maniac (V) Mad Scientist

From: the bigger bedroom
Insane since: Oct 2000

posted posted 01-13-2003 04:09

heh, there's really not much left to do - just call the function.

here's the whole html for the page i wrote - the text box is on the page to show that the score function only looks at radio buttons, and the button is there to call the function.

code:
<html>
<head>


<script>

function checkkit() {
score = new Number(0); //start score at zero.
for(i=0;i<document.forms[0].elements.length;i++) { //for every element in the form
if(document.forms[0].elements[i].type=='radio') { //if the element is a radio button
if(document.forms[0].elements[i].checked) { //and the button is checked
score = score + parseInt(document.forms[0].elements[i].value); //add that button's value to the score.
}
}
}
alert(score); //then alert the final score.
} // end function checkkit

</script>
</head>

<body>
<form name='myform'>
<input type=radio name='rad1' value='1'>1
<input type=radio name='rad1' value='2'>2
<input type=radio name='rad1' value='3'>3<br>

<input type=radio name='rad2' value='1' checked>1
<input type=radio name='rad2' value='2'>2
<input type=radio name='rad2' value='3'>3<br>

<input type=text name='textbox' value='this one for testing only!'><br>
<input type=button value='clicky' name='butt' onclick='checkkit()'>
</form>
</body>
</html>



« BackwardsOnwards »

Show Forum Drop Down Menu