[CODE]<script type="text/javascript">
function focus()
{
document.homepage.name.focus();
}
function checkall()
{
with(document.homepage)
{
// Check for blank fields
if ((name.value=="")||(password.value=="")||(name.length>20)||(password.length>20))
{
alert("Please complete all fields")
alert("Fields cannot contain more than 20 characters!")
return false;
}
"focus" and "name" are reserved JavaScript words. You might be able to get away with naming an element "name", but I recommend changing it to something like "fullName", or something like that.
You'll have to change the name of the first function, though; function focus() won't fly, since .focus() exists.
Keeping the number of alerts to a minimum (preferably one) would be less annoying to the users.
<script type="text/javascript">
function getfocus()
{
document.homepage.name.focus();
}
function checkall()
{
with(document.homepage)
{
// Check for blank fields
if ((name.value=="")||(password.value=="")||(name.length<10)||(password.value<10))
{
alert("Please complete all fields properly")
return false;
}
else
{
alert("Welcome!");
return true;
}
}
}
</script></head><body onLoad="focus()"><h1>Welcome to the Casino:</h1><p>Enter your Username and Password below.</p><p>Username and Password must not have more than 20 characters each.</p><form name="homepage" method="post" action="login.php" onSubmit="return checkall()"><table border="0"><tr><td width="120">Username:</td><td><input type="text" name="name" maxlength="20"></td></tr><tr><td width="120">Password:</td><td><input type="password" name="password" maxlength="20"></td></tr><tr><td> </td></tr><tr><td colspan="2" align="center"><input type="Submit" name="submit" value="Submit"><input type="Reset" name="reset" value="Reset"></td></tr></table></form>
When I click submit when the fields are empty I get the "Please complete all fields properly" alert, but when I enter less than 10 characters in each field I get the welcome alert.
Bookmarks