Hey guys i'm really in need of help. I'm creating a test in javascript on the topic php and the only thing i can't get working is the text field aka question 3. Here is the code, <!-- On-line Php Test --> <html> <head> <title>On-line Php Test</title> <style type="text/css"> body { background-color: green; color: wheat; font-size: 20; } #divqu1 { position: absolute; top: 10%; left: 10%; height: 10% width: 20%; } #divqu2 { position: absolute; top: 10%; left: 60%; height: 40%; width: 40%; } #divqu3 { position: absolute; top: 30%; left: 10%; height: 10%; width: 20%; } #divqu4 { position: absolute; top: 55%; left: 60%; height: 40%; width: 20%; } #divqu5 { position: absolute; top: 50%; left: 10%; height: 10%; width: 20%; } #divmt { position: absolute; top: 410%; left: 40%; height: 1%; width: 20%; } #divys { position: absolute; top: 410%; left: 90%; height: 1%; width: 130%; } </style> <script type="text/javascript"> function marktest() { //alert("inside marktest"); var yourmark = 0, totalmark = 6; //mark question 1 yourmark = yourmark + parseInt (document.frmTest.cboQu1.value); //mark question 2 if (document.frmTest.optQu2[3].checked == true) { yourmark = yourmark + 1; } //mark question 3 if (document.frmTest.txtQu3.value == "while (PHP: Hypertext Preprocessor)") { yourmark += 1; } //mark question 4 if (document.frmTest.chk1.checked == true) { yourmark = yourmark + 0; } if (document.frmTest.chk3.checked == true) { yourmark = yourmark + 1; } if (document.frmTest.chk2.checked == true) { yourmark = yourmark + 1; } if (document.frmTest.chk4.checked == true) { yourmark = yourmark + 0; } //mark question 5 yourmark = yourmark + parseInt (document.frmTest.cboQu5.value); document.getElementById ("divys").innerHTML = "Your score: " + yourmark + " out of " + totalmark; } </script> </head> <body> <h1 align="center">On-line Php Test</h1> <form name="frmTest"> <div id="divqu1"> 1. Choose the true statement from the <br />drop down list. <br /> <select name="cboQu1"> <option value="0">Select Your Answer </option> <option value="0">Php is a client side language</option> <option value="1">Php is a server side language</option> <option value="0">Php is a client side and server side language</option> </select> </div> <div id="divqu2"> 2. Choose the correct output displayed by the following fragment of php. <br /> fragment of php code <br /> $num=4; <br /> print(25% $num); <br /> <input type="radio" name="optQu2" /> 6 <br /> <input type="radio" name="optQu2" /> 5 <br /> <input type="radio" name="optQu2" /> 0 <br /> <input type="radio" name="optQu2" /> 1 <br /> <input type="radio" name="optQu2" /> 6.25 </div> <div id="divqu3"> 3. What does PHP stand for? <br /> <input type="text" name="txtQu3"> </div> <div id="divqu4"> 4. How do you write "Hello World" in PHP <br /><br /> <input type="checkbox" name="chk1"> Document.Write("Hello World"); <br /> <input type="checkbox" name="chk2"> print "Hello World"; <br /> <input type="checkbox" name="chk3"> echo "Hello World"; <br /> <input type="checkbox" name="chk4"> "Hello World"; </div> <div id="divqu5"> 5. All variables in PHP start with which symbol? <br /> <select name="cboQu5"> <option value="0">Select Your Answer </option> <option value="0">&</option> <option value="0">!</option> <option value="1">$</option> </select> <div id="divmt"> <input type="button" name="cmdmark" value="Mark Test" onclick="marktest()" /> </div> <div id="divys"> Your score: /6 </div> </form> </body> </html> Code (markup): I know it's probably a really common mistake but it's driving me nuts i can't figure it out. Many thanks and rep to whoever can help me with this. Cheers.
Question 3 of the test doesn't work. The question is what does php stand for and the answer should be PHP: Hypertext Preprocessor. For each question the user gets right they get 1 mark. But when the user keys that in it doesn't give them a mark. That is the only one that's not working. The javascript code for the question, //mark question 3 if (document.frmTest.txtQu3.value == "while (PHP: Hypertext Preprocessor)") { yourmark += 1; } Code (markup): And here is the html code for the question, <div id="divqu3"> 3. What does PHP stand for? <br /> <input type="text" name="txtQu3"> </div> Code (markup):
Change //mark question 3 if (document.frmTest.txtQu3.value == "while (PHP: Hypertext Preprocessor)") { yourmark += 1; } Code (JavaScript): to //mark question 3 if (document.frmTest.txtQu3.value == "PHP: Hypertext Preprocessor") { yourmark += 1; } Code (JavaScript):