Its because you have line breaks in the code in the wrong locations.
As a rule of thumb I always use {} when using loops or conditions. As it avoids this sort of issue.
The below code will work.
HTML Code:
<HTML>
<HEAD>
<script type="text/javascript">
function notEmpty(){
var myTextField = document.getElementById('myText');
if(myTextField.value != "fred"){
alert("You entered: " + myTextField.value);
}
else{
alert("Correct");
window.location = "http://www.google.com/";
}
}
</script>
</HEAD>
<BODY>
<input type='text' id='myText' />
<input type='button' onclick='notEmpty()' value='Form Checker' />
</BODY>
</HTML>
Bookmarks