HELP! Simple Javascript Problem, Simpler Me!

N

not

Hello All,

I am trying to develop a relatively simple self-quiz form in
javascript, but I'm having no luck getting it to work.

What I am looking for is a script that allow the user to select one of
three answers for each question, and automatically assign a value to
their answer ("never"=0, "sometimes"=1, "always"=2). There would be
anywhere from ten to thirty questions. I want the script to calculate
the running total, and then display that total at the bottom of the
input section. FYI, there I would add text to the effect of "your
total score is [x]. A score of 0-10 means this, 11-20 means that, and
21-30 means somthing else."

Conceptually it seems so simple to me. But all the scripts I write
(or, actually, find-and-tweak) either over-calculate (in other words,
multiple clicks on a "yes" radio button increase the total) or only
calculate the last set of values (i.e. question 5 out of 5 but not
1-4). Any help would be most appreciated.

Munged code follows. I've stripped it down to its essentials (actually
well beyond that, hence the problem). There's a big hole where the
javascript itself should go. I feel certain there's a straightforward
solution to this. Yet it's seemingly beyond me....

Bill

-----------------------------

<head>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
// End -->
</script>
</head>

<body>

<form method="POST" name="myform">

<table border=1 cellpadding=2>

<tr>
<td align=center>Never</td>
<td align=center>Sometimes</td>
<td align=center>Always</td>
<td>&nbsp;</td>
</tr>

<tr>
<td align=center valign=top><input type="radio" name="1"
onclick="this.form.total.value=0;"></td>
<td align=center valign=top><input type="radio" name="1"
onclick="this.form.total.value=1;"></td>
<td align=center valign=top><input type="radio" name="1"
onclick="this.form.total.value=2;"></td>
<td valign=top>I eat breakfast.
</tr>

<tr>
<td align=center valign=top><input type="radio" name="2"
onclick="this.form.total.value=0;"></td>
<td align=center valign=top><input type="radio" name="2"
onclick="this.form.total.value=1;"></td>
<td align=center valign=top><input type="radio" name="2"
onclick="this.form.total.value=2;"></td>
<td valign=top>I eat lunch.</td>
</tr>

<tr>
<td colspan=4>Your score is: <input type="text" name="total"
readonly onFocus="this.blur();"></td>
</tr>

</table>

</form>

</body>
 
M

Mick White

Hello All,

I am trying to develop a relatively simple self-quiz form in
javascript, but I'm having no luck getting it to work.

What I am looking for is a script that allow the user to select one of
three answers for each question, and automatically assign a value to
their answer ("never"=0, "sometimes"=1, "always"=2). There would be
anywhere from ten to thirty questions. ...

http://www.mickweb.com/javascript/forms/radios/weightedSurvey.html
Mick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top