By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,251 Members | 2,727 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,251 IT Pros & Developers. It's quick & easy.

HELP! Simple Javascript Problem, Simpler Me!

P: n/a
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>
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
no*@this.time wrote:
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/fo...tedSurvey.html
Mick
Jul 23 '05 #2

P: n/a
not
On Thu, 06 Jan 2005 21:50:53 GMT, Mick White
<mw***********@rochester.rr.com> wrote:
http://www.mickweb.com/javascript/fo...tedSurvey.html


Amazing. Thank you VERY much.
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.