View Full Version : Calculate score problem

06-03-2005, 12:20 PM
I'm trying to create a javascript quiz where users have to type the correct numbers in boxes, one of which is to be left blank.
In the example there are 3 boxes, and the correct answer is 3 in the first box and 2 in the last. The middle box is to be left blank.
When the boxes are filled in correctly, there is a visual and audible response.
If I set the value of the blank box to "" (i.e. none), the script works fine; but there is a problem: if the user clicks the check button, he/she can see which is the blank and the quiz is much easier.
This can be solved by setting the value of the blank to " " (i.e. a space). There is then no visual clue if the user clicks Check before starting the quiz - fine, that's what I want.
But this means that the Check function will not be able to arrive at 100%, since the user's input in the blank box does not correspond to the hidden value.
So what I need is to change the calculate score script so it ignores the value in the blank box.
Can anyone help? I would be very grateful.

<table id="tab1" border="0" cellspacing="0" cellpadding="2">
<tr align="center">
<td width="50"><input type="hidden" value="3"><input type="text" style="border:1px solid;text-align:center;" size="1"><span></span></td>
<td width="50"><input type="hidden" value=""><input type="text" style="border:1px solid;text-align:center;" size="1"><span></span></td>
<td width="50"><input type="hidden" value="2"><input type="text" style="border:1px solid;text-align:center;" size="1"><span></span></td>

<table border="0" cellspacing="0" cellpadding="2">
<form id="f"><input type="button" value="Check" onclick='Check()'></form>

<script type="text/javascript">

function playSound(soundobj) {
var thissound=document.getElementById(soundobj);

var TPoint=0;
function Check() {
var total=document.getElementById("tab1").getElementsByTagName("input").length/2;
var e=0;
var draw = document.getElementsByTagName("span");
var inputs = document.getElementsByTagName("input");
for (var i=0;i<inputs.length;i++)
if ( inputs.item(i).type=="text")
if (trim(inputs.item(i).value)==inputs.item(i-1).value)
else if (inputs.item(i).value != "")
if (TPoint==100)
function trim(s){
return s.replace(/^\s+/,'').replace(/\s+$/,'');

<embed src="right.mp3" autostart=false hidden=true name="right"
<embed src="wrong.mp3" autostart=false hidden=true name="wrong"

06-04-2005, 06:41 AM
I might be way off base, but if you simply do not want to check when user clicks check prior to entering anything then just add a text to make sure i != 3 in the first winding if statement...

Presumably the others errors and correpsonding outputs are sufficient such that it is not just a one click too see the expected answer as per Q...

Hmm.. not sure what the status quo is here since I'm new my self, but couple of suggestions, are, formatting, and then presenting Q in simpliest / plain methods ( i.e lose the windings...).

Also, even though it took me a few mins to work out the fancy javascript calculation it dawned on me that the answers are plainly there in the hidden elements, so couldn't the javascript been a bit more straight forward ... anyway probably because I didn't start from scratch etc...


06-04-2005, 12:11 PM
Thanks for the suggestions. I'm working on it ...

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum