Forum Moderators: open
<head>
<script type="text/javascript">
function validate(loginform)
{
var usernameLen=loginform.username.value.length;
var passwordLen=loginform.password.value.length;
if (!usernameLen>0)
{
changeColor("username");
changeColor("password");
window.alert("Username is missing!");
return false;
}
else
if(!passwordLen>0)
{
changeColor("password");
window.alert("Password is missing!");
return false;
}
else
{
return true;
}
}
function changeColor(id)
{
element = document.getElementById(id);
element.style.background = "lightyellow";
}
</script>
</head>
inside body section
<form action="checkUser" name="loginform" method="post" onsubmit="return validate()">
User Name:<input type="text" id="username" name="username">
Password :<input type="password" id="password" name="password">
<br>
<input type="submit" value="submit">
</form>
and a warm welcome to these forums. ;)
Add this as indicated...
<form action="checkUser" name="loginform" method="post" onsubmit="return validate(this)">