Code Help, Please

T

Teach

I am designing a small quiz, and everything works just fine except one
small problem. If a user inputs any uppercase letters at all, the
check function marks the response incorect. Below is the snippet of
code for the function check. Can anyone tell me how to modify it to
ignore "case". The user needs to be able to input in both upper and
lower case.

Thanks in advance. Here is the snippet of code:

function check(){

for(i=0;i<answer.length;i++){
if(document.myform.elements.value.toLowerCase()==answer){
score++;
}else{
if(document.myform.elements.value!=""){
document.myform.elements.value="";
}
}

}
alert(score + " out of " + answer.length + ".");
score = 0;
}

//Put the correct answers into all the fields

function show(){

for(i=0;i<answer.length;i++){
document.myform.elements.value = answer;
}

}
 
B

Bob Lehmann

Set the answer to lowercase also...
if(document.myform.elements.value.toLowerCase()==answer.toLowerCase())
{
score++;
}

Bob Lehmann
 
T

Teach

Thank you very much for your help and assistance Bob. It worked perfectly.
Set the answer to lowercase also...
if(document.myform.elements.value.toLowerCase()==answer.toLowerCase())
{
score++;
}

Bob Lehmann

Teach said:
I am designing a small quiz, and everything works just fine except one
small problem. If a user inputs any uppercase letters at all, the
check function marks the response incorect. Below is the snippet of
code for the function check. Can anyone tell me how to modify it to
ignore "case". The user needs to be able to input in both upper and
lower case.

Thanks in advance. Here is the snippet of code:

function check(){

for(i=0;i<answer.length;i++){
if(document.myform.elements.value.toLowerCase()==answer){
score++;
}else{
if(document.myform.elements.value!=""){
document.myform.elements.value="";
}
}

}
alert(score + " out of " + answer.length + ".");
score = 0;
}

//Put the correct answers into all the fields

function show(){

for(i=0;i<answer.length;i++){
document.myform.elements.value = answer;
}

 
Top