I found a PHP script somewhere on the net, which I have adapted to suit my needs. What I need it to do is, when someone enters the correct answer, and presses enter, it should move on to another URL. I can't get it to do this though, but it does work if I click the submit button. Can anyone help?
Here is the full script:
<html>
<head>
<title>Testing</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
var theElements = new Array();
function checkForm(theForm) {
var i;
var theName;
var correct = true;
var rightOrWrong;
for(i=0;theForm.elements;i++) {
theName = theForm.elements.name;
if(theName.substr(0,5)=="INPUT") {
if(theName=="INPUT") {
if(theForm.elements.value=="" || theForm.elements.value==" ") {
rightOrWrong = true;
} else {
rightOrWrong = false;
}
} else {
rightOrWrong = theName.substr(5,theName.length-5)==theForm.elements.value;
}
if(!rightOrWrong) {
theElements[theElements.length] = theForm.elements;
setTimeout("clearElement(" + (theElements.length-1) + "," + "'INPUT'" + ")",1000);
correct = false;
}
} else if(theName.substr(0,6)=="SELECT") {
if(theForm.elements.options[theForm.elements.selectedIndex].value!=1) {
theElements[theElements.length] = theForm.elements;
setTimeout("clearElement(" + (theElements.length-1) + "," + "'SELECT'" + ")",1000);
correct = false;
}
}
}
if(correct) {
document.location.href="http://www.planet-q.com";
}
}
function clearElement(index,type) {
if(type=="INPUT") {
theElements[index].value = "";
} else if(type=="SELECT") {
theElements[index].selectedIndex = 0;
}
}
//-->
</script>
<style type="text/css">
</style>
</head>
<body bgcolor="#FFFFFF">
<div align="center"></div>
<form method="post" action="">
<p><strong><font face="Geneva, Arial, Helvetica, sans-serif">What is the answer?</font></strong></p>
<p>
<input type="text" name="INPUTanswer" size="50" maxlength="100">
<input type="button" name="BUTTON" value="Submit" onClick="checkForm(this.form)"></font>
</p>
</form>
</body>
</html>
Thanks.