Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - quiz scoring javascript
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Topic Closedquiz scoring javascript

 Post Reply Post Reply
Author
red9 View Drop Down
Newbie
Newbie


Joined: 19 August 2003
Status: Offline
Points: 1
Direct Link To This Post Topic: quiz scoring javascript
    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
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.