Simple HTML Form Validation with JavaScript

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Simple JavaScript Form Validation</title>
</head>
<html>

<script language=”JavaScript” type=”text/JavaScript”>

function validation(thisform)
{
if(thisform.Name.value==”)
{
alert(“Name is required.”);
return false;
}
if(thisform.Address.value==”)
{
alert(“Address  is required.”);
return false;
}

//if all is OK submit the form

thisform.submit();
}
</script>
<?php
//Your database insertion  code
?>

<form name=”myform” id=”myform” method=”post”>

<table width=”500″ border=”0″ cellspacing=”0″ cellpadding=”0″>
<tr>
<td width=”121″>Name</td>
<td width=”379″><input name=”Name” type=”text” id=”Name” /></td>
</tr>
<tr>
<td>Address</td>
<td><input name=”Address” type=”text” id=”Address” /></td>
</tr>
<tr>
<td><input name=”Submit” type=”button” id=”Submit” onclick=”validationvalidation(this.form)” value=”Submit” /></td>

<td>&nbsp;</td>
</tr>
</table>
</form>

<body>
</body>
</html>

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*
Website