Welcome to the forum!
Get rid of (or rename) the name "submit" on the submit button (you can leave the ID set to submit if you like).
Then, set your submit button's type to "submit" rather than "button."
Then use the javascript function call for the "onsubmit" attribute of the form element rather than the "onclick" attribute of the submit button (after all, what if the user hits enter rather than clicking the submit button?). And you can save a step by using "
return verify();" (as opposed to just "verify();") as the javascript call. Then you don't even need to write in anything for form submission in your function, you just return true when it's good and false when it's not. And then everything should work as you intended
Cleaned up and properly working version is below:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Project Rival - Authentication</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function verify() {
var themessage = "Please enter your";
if (document.getElementById('user').value=="") {
themessage = themessage + " username";
}
if (document.getElementById('user').value=="" && document.getElementById('pass').value=="") {
themessage = themessage + " and";
}
if (document.getElementById('pass').value=="") {
themessage = themessage + " password";
}
//alert if fields are empty and cancel form submit
if (document.getElementById('user').value!="" && document.getElementById('pass').value!="") {
return true;
}
else {
document.getElementById("error").innerHTML = themessage;
return false;
}
}
</script>
</head>
<body>
<div id="container">
<div id="login_box_top"> </div>
<div id="logo"><img src="images/projectrival.jpg" alt="Project Rival" style="width:150px" /></div>
<div id="error"></div>
<div id="login">
<form action="login.php" method="post" id="login_form" onsubmit="return verify();">
<div>
<input name="user" class="input" id="user" type="text" size="30" maxlength="30" /><br /><br />
<input name="pass" class="input" id="pass" type="password" size="30" maxlength="30" /><br /><br />
<input id="submit" type="submit" value="Login" />
</div>
</form>
</div>
<div id="login_box_bottom"> </div>
<div id="copy"><p>© Martin Day 2011</p></div>
</div>
</body>
</html>
Note that you could still stand to clean up your if/else logic to reduce code, but this is functionally correct now.