PDA

View Full Version : How can you increase a value in a textbox on every correct answer?


tanneman
10-01-2002, 10:25 AM
Hi everybody

My name is Tanju and I am still learning javascript. As I was working on a script I bumped into a little problem. I have to make an E-learning site. Very simple acctually but the problem is whenever the user clicks on the correct answer a textbox which starts with the value "0" must increase with 1...This textbox is placed into an other frame because every question is a different plage.

This is the code that I used to make the quiz:

var ans = new Array; //those are the correct answers
ans[1] = "b";
ans[2] = "a";
ans[3] = "c";
ans[4] = "a";
ans[5] = "c";

//this loads when I click on a radiobutton of the multiple choice quiz

function MyCheck(question, answer, page){

if (answer == ans[question]) {
parent.question.location='question'+page+'.html';
for (i=0;i<parent.tellen.document.score.juiste.length;i++){

//now I don't know what to do...
//parent.tellen.document.score.juiste.value =

}

} else {
parent.question.location='question'+page+'.html';

}


}

so, everything works except the increasing of the value in the textbox...
___________________________________________
This is the body code:

<form name="quiz" method="post" action="">
<br>
<p>
<span class="tmain2">1. De gevaren van gassen</span><br>
<span class="tmain">1.1 Verstikkingsgevaar</span></p>

<table cellspacing="0" cellpadding="0" border="0">

<tr><td width="47">&nbsp;
<td valign="middle" class="tmain" colspan="5" >1. Hoeveel zuurstof omvat de omgevingslucht?
<tr><td width="47" height="20">&nbsp;<td width="24" height="20"><input type="radio" name="chosen" value="a" onclick="MyCheck(1, this.value, 2)"><td height="20" class="tmain" colspan="4"> 11%
<tr><td width="47" height="20">&nbsp;<td height="20"><input type="radio" name="chosen" value="b" onclick="MyCheck(1, this.value, 2)"><td class="tmain" height="20" colspan="4">21%
<tr><td width="47" height="20">&nbsp;<td height="20"><input type="radio" name="chosen" value="c" onclick="MyCheck(1, this.value, 2)"><td class="tmain" height="20" colspan="5"> 31%
<tr><td width="47" height="20">&nbsp;<td height="20" align="center" valign="bottom">&nbsp;
<td width="316" height="20" colspan="3" align="left" valign="middle" class="tablebody2">
<div id="oef1Msg"></div>



</table>

</form>

____________________________________

And this is the body code of the Textbox put into a different frame

<form name="score" >
<br><span class="tmain">score:</span> &nbsp;&nbsp;<input type="text" size="8" value="0" name="juiste" style="FONT-SIZE: 9px; COLOR: #ffffff; FONT-FAMILY: verdana, geneva, arial, helvetica; background-color:#2E356C"></form>

_______________________________________

Many Thanks
Best regards

glenngv
10-01-2002, 10:29 AM
parent.tellen.document.score.juiste.value = parseInt(parent.tellen.document.score.juiste.value) + 1;

tanneman
10-01-2002, 10:56 AM
hi glenn

Thanks for your reply...but it seems not te be working. I will try to figure out what I am doing wrong. Any suggestions are welcome

thanks

glenngv
10-01-2002, 11:54 AM
is tellen the name of the frame where the textbox is?

you can try this also:

top.frames["tellen"].document.score.juiste.value = parseInt(top.frames["tellen"].document.score.juiste.value) + 1;

tanneman
10-01-2002, 12:16 PM
thanks Glenn

It works now...