Tuesday, January 22, 2008

joys of java

i'll mail 50 cents to anyone who can tell me what is wrong with this javascript
it will never do the "for"'s correctly
ps: has unicode japanese fonts.


function scorePage()
{

question1=document.forms[0].question1;
question2=document.forms[0].question2;
question3=document.forms[0].question3;
correct = 0;
txt = ""
for (i=0; i< question1.length; ++ i)
{
if (question1[i].checked && question1[i]=="1")
{
alert("this was right");
correct++;
txt = txt + question1[i];
}


}
for (i=0; i< question2.length; ++ i)
{
if (question2[i].checked && question2[i]=="1")
{
correct++;
txt = txt + question2[i];
}

}
for (i=0; i< question3.length; ++ i)
{
if (question3[i].checked && question3[i]=="1")
{
correct++;
txt = txt + question3[i];
}

}
//txt should equal whatever was checked by the student... but it doesn't
document.getElementById("score").value="You scored a " + correct + " out of 3!";
document.getElementById("answers").value=txt;
}

No comments: