Print Page | Close Window

quiz scoring javascript

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Web Design Discussion
Forum Description: Discussion on web design and development subjects.
URL: https://forums.webwiz.net/forum_posts.asp?TID=5139
Printed Date: 29 March 2026 at 12:51am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: quiz scoring javascript
Posted By: red9
Subject: quiz scoring javascript
Date Posted: 20 August 2003 at 2:50am
Edit Delete
I'm trying to get a simple numerical result from three
questions. One is a select box, the other two are
radio buttons. Ideally, I'd like the number result to
correspond to opening a particular html page, but for
now I can't even get the number result to work.
I'm using this code:
<script TYPE="text/javascript">
<--
var t;
function tot()
{
t=0;
for(i=0;i<3;i++)
{
for(j=1;j<4;j++)
{
if(eval("document.f.r"+j+"["+i+"].checked"))
t+=parseInt(eval("document.f.r"+j+"["+i+"].value"));
}
}
rpt=confirm("Your score is : "+t+"\n\nReset form ?");
if(rpt)document.f.reset();
}
// -->
and the form is looking like this:
----------

          <FORM NAME="f">
               <SELECT NAME="r1">
                <OPTION NAME="r1" value="0" selected>-
SELECT AGE -</OPTION>
                <OPTION NAME="r1" value="5">0-5</OPTION>
                <OPTION NAME="r1" value="10">6-10</OPTION>
                <OPTION NAME="r1"
value="20">11-15</OPTION>
                <OPTION NAME="r1"
value="30">16-20</OPTION>
                <OPTION NAME="r1"
value="40">21-35</OPTION>
               </SELECT>

<input type="radio" NAME="r2" VALUE="2">FICTION
            <input type="radio" NAME="r2"
VALUE="1">NON-FICTION

<input type="radio" NAME="r3" VALUE="1">MALE
            <input type="radio" NAME="r3"
VALUE="2">FEMALE

<INPUT TYPE="button" VALUE="Get result"
ONCLICK="tot()">

----------
Doesn't seem to work at all, I would really appreciate
some help, perhaps it's just a syntax error I've
overlooked, being new to such things :-)
Any tips on how to get the browser to then display a
particular html page depending on the score would
also be appreciated if anyone is feeling generous.
Thanks so much,
in anticipation x



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net