Monday 1 April 2013

Simple HTML form with JavaScript alert Validation

<html>
<head>
<title>Welcome form</title>
<script type="text/javascript">

function validateForm()
{
var a=document.forms["Amanforms"]["firstname"].value;
if(a==null || a=="")
 {
  alert("Please fill the first name...");
  return false;
 }
var b=document.forms["Amanforms"]["lastname"].value;
if(b==null || b=="")
 {
  alert("Please fill the last name...");
  return false;
 }
var c=document.forms["Amanforms"]["password"].value
if(c==null || c=="")
 {
  alert("Please fill the password...");
  return false;
 }
var d=document.forms["Amanforms"]["address"].value
if(d==null || d=="")
 {
  alert("please fill the address...");
  return false;
 }
var e=document.forms["Amanforms"]["phone"].value
if(e==null || e=="")
 {
 alert("Please fill the phone number...");
 return false;
 }
var f=document.forms["Amanforms"]["mobile"].value
if(f==null || f=="")
 {
  alert("Please fill the mobile number...");
  return false;
 }
}

</script>
</head>
<body>
<form action="test.html" method="post" name="Amanforms"
onsubmit="return validateForm()"
>
<table align="center">
<img
src="C:\Documents and Settings\Tarun\My Documents\My Pictures\corporate.jpg"
alt="corporate.jpeg"
/>
<tr>
<td><b>First name:</b>
</td>
<td><input type="text" name="firstname" />
</td>
</tr>
<tr>
<td><b>Last name:</b>
</td>
<td><input type="text" name="lastname" />
</td>
</tr>
<tr>
<td><b>password:</b>
</td>
<td><input type="password" name="password" />
</td>
</tr>
<tr>
<td><b>Address:</b>
</td>
<td><input type="text" name="address" />
</td>
</tr>
<tr>
<td><b>Phone no:</b>
</td>
<td><input type="Digit" name="phone" />
</td>
</tr>
<tr>
<td><b>Mobile no:</b>
</td>
<td><input type=" Digit" name="Mobile" />
</td>
</tr>
<tr>
<td><button type="submit">submit</button>
</td>
<td><button type="cancle">cancle</button>
</td>
</tr>
</table>
</form>
</body>
</html>

No comments:

Post a Comment