<html>
<head>
<title>Simple Client Side Validation</title>
<script type="text/javascript">
function valid()
{
if(myform.name.value=="")
{
alert("enter your name");
return false;
document.myform.name.focus();
}
if(myform.contact.value=="")
{
alert("enter your contact");
return false;
document.myform.contact.focus();
}
if(isNaN(myform.contact.value))
{
alert("enter numeric value in contact");
return false;
document.myform.contact.focus();
}
if(myform.city.value=="")
{
alert("enter your city");
return false;
document.myform.city.focus();
}
if(myform.email.value=="")
{
alert("enter your email");
document.myform.email.focus();
return false;
}
if(myform.address.value=="")
{
alert("enter your address");
document.myform.address.focus();
return false;
}
}
</script>
</head>
<body>
<form name="myform" action="submit.php" method="post" onsubmit="return(valid());" >
Name <input type="text" name="name" >
contact<input type="text" name="contact">
city<input type=text name="city">
email<input type=text name="email">
Address<textarea rows=5 cols=5 name=address>
</textarea>
<input type=submit name=submit>
</form>
</body>
</html>
<head>
<title>Simple Client Side Validation</title>
<script type="text/javascript">
function valid()
{
if(myform.name.value=="")
{
alert("enter your name");
return false;
document.myform.name.focus();
}
if(myform.contact.value=="")
{
alert("enter your contact");
return false;
document.myform.contact.focus();
}
if(isNaN(myform.contact.value))
{
alert("enter numeric value in contact");
return false;
document.myform.contact.focus();
}
if(myform.city.value=="")
{
alert("enter your city");
return false;
document.myform.city.focus();
}
if(myform.email.value=="")
{
alert("enter your email");
document.myform.email.focus();
return false;
}
if(myform.address.value=="")
{
alert("enter your address");
document.myform.address.focus();
return false;
}
}
</script>
</head>
<body>
<form name="myform" action="submit.php" method="post" onsubmit="return(valid());" >
Name <input type="text" name="name" >
contact<input type="text" name="contact">
city<input type=text name="city">
email<input type=text name="email">
Address<textarea rows=5 cols=5 name=address>
</textarea>
<input type=submit name=submit>
</form>
</body>
</html>
No comments:
Post a Comment