amanbatra
Technical User
- Jul 4, 2008
- 4
hello..,
can any1 help me how to get hold of form field validation??
i have a code below but it doesn't work..
can u suggest me why..
<html>
<head>
<script type="text/javascript">
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
{alert(alerttxt);return false;}
else {return true}
}
}function validate_form(thisform)
{
with (thisform)
{
if (validate_required(firstname,"Firstname must be filled out!")==false)
{email.focus();return false;}
}
with (thisform)
{
if (validate_required(lastname,"lastname must be filled out!")==false)
{email.focus();return false;}
}
with (thisform)
{
if (validate_required(email,"Email must be filled out!")==false)
{email.focus();return false;}
}
with (thisform)
{
if (validate_required(email,"Email must be filled out!")==false)
{email.focus();return false;}
}
}
</script>
</head>
<body>
<form action="submitpage.htm"
onsubmit="return validate_form(this)"
method="post">
FIRSTNAME:<input type="text name="firstname"size="40"><br>
<br>
<br>
LASTNAME: <input type="text name="lastname"size="40"><br>
<br>
<br>
GENDER:<br>
MALE: <input type="radio" name="sex" value="male"><br>
FEMALE:<input type="radio" name="sex" value="female"><br>
<br>
<br>
*COURSE APPLYING FOR:<br>
B-tech:
<input type="radio" name="course applying for" value="B-tech">
<br>
M-tech:
<input type="radio" name="course applying for" value="M-tech">
<br>
<br>
<br>
Email: <input type="text" name="email" size="30">
<input type="submit" value="Submit">
</form>
</body>
</html>
any replies will b appreciated
can any1 help me how to get hold of form field validation??
i have a code below but it doesn't work..
can u suggest me why..
<html>
<head>
<script type="text/javascript">
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
{alert(alerttxt);return false;}
else {return true}
}
}function validate_form(thisform)
{
with (thisform)
{
if (validate_required(firstname,"Firstname must be filled out!")==false)
{email.focus();return false;}
}
with (thisform)
{
if (validate_required(lastname,"lastname must be filled out!")==false)
{email.focus();return false;}
}
with (thisform)
{
if (validate_required(email,"Email must be filled out!")==false)
{email.focus();return false;}
}
with (thisform)
{
if (validate_required(email,"Email must be filled out!")==false)
{email.focus();return false;}
}
}
</script>
</head>
<body>
<form action="submitpage.htm"
onsubmit="return validate_form(this)"
method="post">
FIRSTNAME:<input type="text name="firstname"size="40"><br>
<br>
<br>
LASTNAME: <input type="text name="lastname"size="40"><br>
<br>
<br>
GENDER:<br>
MALE: <input type="radio" name="sex" value="male"><br>
FEMALE:<input type="radio" name="sex" value="female"><br>
<br>
<br>
*COURSE APPLYING FOR:<br>
B-tech:
<input type="radio" name="course applying for" value="B-tech">
<br>
M-tech:
<input type="radio" name="course applying for" value="M-tech">
<br>
<br>
<br>
Email: <input type="text" name="email" size="30">
<input type="submit" value="Submit">
</form>
</body>
</html>
any replies will b appreciated