Javascript validation for registration form
<head>
<title>REGISTRATION</title>
<style>
.margin
{
margin-top:100px;
margin-bottom:100px;
margin-left:150px;
margin-left:150px;
}
</style>
<script type="text/javascript">
function validate()
{
if(document.getElementById('name').value=='')
{
alert("please enter a name");
document.getElementById('name').focus();
return false;
}
if(document.getElementById('username').value=='')
{
alert("please enter a username");
document.getElementById('username').focus();
return false;
}
if(document.getElementById('password').value=='')
{
alert("please enter a password");
document.getElementById('password').focus();
return false;
}
if(document.getElementById('email').value=='')
{
alert("please enter a email");
document.getElementById('email').focus();
return false;
}
if(document.getElementById('address').value=='')
{
alert("please enter a address");
document.getElementById('address').focus();
return false;
}
return true;
}
</script>
</head>
<body>
<form action="login.html"method="post" onsubmit="return validate()";>
<table width="50%"border="1">
<tr>
<td>
<table width="50%" border="0" align="center" class="margin">
<tr>
<td colspan="2" align="center">REGISTRATION</td>
</tr>
<tr>
<td>NAME:</td>
<td><input type="text" name="name" id="name" size="20"></td>
</tr>
<tr>
<td>USERNAME:</td>
<td><input type="text" name="username" id="username" size="20"></td>
</tr>
<tr>
<td>PASSWORD:</td>
<td><input type="text" name="password" id="password" size="20"></td>
</tr>
<tr>
<td>EMAIL:</td>
<td><input type="text" name="email" id="email" size="20"></td>
</tr>
<tr>
<td>ADDRESS:</td>
<td valign="top"><textarea rows="10" cols="20" name="address" id="address"></textarea></td>
</tr>
<tr>
<td align="center"><input type="submit" name="submit" id="submit"value="register"></td>
</tr>
</form>
</table>
</table>
</body>
</html>