Popular Posts

Get widget

Tuesday 12 February 2013

JavaScript Validation

Add javascript validation in your website

JavaScript can be used to validate data in HTML forms before sending off the content to a server.
Form data that typically are checked by a JavaScript could be:
  • has the user left required fields empty?
  • has the user entered a valid e-mail address?
  • has the user entered a valid date?
  • has the user entered text in a numeric field?


<html><head><title>Free Trial</title>
<style type="text/css">     .txt { color:#fff; }     </style>
<script language="JavaScript">
function validate()
{

if(document.info.nm.value == "")
{
alert("Please enter name");
return false;
}
if(document.info.mobile.value == "")
{
alert("Please enter mobile number");
return false;
}
}
</script>
</head>

<body bgcolor="#000000">
<form name="info" action="send.php" method="post" onsubmit="return validate()">
<table border="0" cellpadding="4" cellspacing="0" width="100%">
<tr>
<th colspan="2" class="txt"> <img src="images/free_trial.gif" /></th>
</tr>

<tr>
<td class="txt"><br>Name:&nbsp;</td>
<td><br><input type="text" name="nm" /></td>
</tr>
<tr>
<td class="txt">Mobile Number:&nbsp;</td>
<td><input type="text" name="mobile" maxlength="10" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Submit" /></td>
</tr>
</table></form></body></html>


JAVASCRIPT CODE

0 comments:

Post a Comment