Hello,
I've done the following:
Form HTML area:
<html>
<head>
<title>JavaScript Form Validation Example</title>
<style type="text/css">
body
{
background:white;
font-size:12px;
font-family:arial;
}
table
{
background:navy;
color:white;
font-weight:bold;
}
</style>
</head>
<body>
<table border="1">
<tr>
<td>Name:</td>
<td><input type="text" name="fullName" length="25"></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="email" length="25"></td>
</tr>
<tr>
<td>Phone Number</td>
<td><input type="text" name="phoneNum" length="25"></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Submit"></td>
<td><input type="reset" name="reset"></td>
</tr>
</table>
</body>
</html>
Form Javascript Area:
function validateForm(contact)
{
if(document.forms.contact.fullName.value=="")
{
alert("Please enter your full name.");
document.forms.contact.fullName.focus();
return false;
}
if(document.forms.contact.email.value=="")
{
alert("Please enter your email address.");
document.forms.contact.email.focus();
return false;
}
if(document.forms.contact.phoneNum.value=="")
{
alert("Please enter your phone number.");
document.forms.contact.phoneNum.focus();
return false;
}
}
Form tag attachment:
onSubmit="return validateForm(contact);"
It wont do the validation thing but goes directly to the submitted page.
Can anyone tell me what i'm doing wrong :blush: ?
I've done the following:
Form HTML area:
<html>
<head>
<title>JavaScript Form Validation Example</title>
<style type="text/css">
body
{
background:white;
font-size:12px;
font-family:arial;
}
table
{
background:navy;
color:white;
font-weight:bold;
}
</style>
</head>
<body>
<table border="1">
<tr>
<td>Name:</td>
<td><input type="text" name="fullName" length="25"></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="email" length="25"></td>
</tr>
<tr>
<td>Phone Number</td>
<td><input type="text" name="phoneNum" length="25"></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Submit"></td>
<td><input type="reset" name="reset"></td>
</tr>
</table>
</body>
</html>
Form Javascript Area:
function validateForm(contact)
{
if(document.forms.contact.fullName.value=="")
{
alert("Please enter your full name.");
document.forms.contact.fullName.focus();
return false;
}
if(document.forms.contact.email.value=="")
{
alert("Please enter your email address.");
document.forms.contact.email.focus();
return false;
}
if(document.forms.contact.phoneNum.value=="")
{
alert("Please enter your phone number.");
document.forms.contact.phoneNum.focus();
return false;
}
}
Form tag attachment:
onSubmit="return validateForm(contact);"
It wont do the validation thing but goes directly to the submitted page.
Can anyone tell me what i'm doing wrong :blush: ?