How to make this code more flexible

farcry51

Member
Joined
Oct 24, 2010
Messages
4
Kin
0💸
Kumi
0💴
Trait Points
0⚔️
Hey i've been developing a javascript test and am stuck on one little thing. There is a question that asks for "What does php stand for?" and the answer is "PHP:Hypertext Preprocessor" but it also stands for "Parsing Hypertext Preprocessor".

My question is how would i code it so that it allows both those answers and the user can type the answer in both lower and uppercase. Heres the code,

HTML Code:

Code:
<div id="divqu3"> 
  3. What does PHP stand for?
  <br /> 
  <input type="text" name="txtQu3"> 
  </div>
Javascript:

Code:
//mark question 3
    if (document.frmTest.txtQu3.value == "PHP: Hypertext Preprocessor")
    {
    yourmark += 1;
    }
Thanks for any help.
 

gamahiro

Active member
Supreme
Joined
Jul 8, 2010
Messages
32,579
Kin
0💸
Kumi
0💴
Trait Points
0⚔️
Awards
if()
else if()
else()
...for the 1st part. For the second part I'm not sure the best way to do it. Maybe force it either upper or lower.
 

Dr Octogonapus

Active member
Regular
Joined
Nov 10, 2009
Messages
1,522
Kin
0💸
Kumi
0💴
Trait Points
0⚔️
Is this what your after?

Code:
//mark question 3
    if (document.frmTest.txtQu3.value.toLowerCase() == "php: hypertext preprocessor" || document.frmTest.txtQu3.value.toLowerCase() ==  "parsing hypertext preprocessor")
    {
    yourmark += 1;
    }
Don't forget to rep me and gammy :p
 
Top