Who doesnt need to implement a data validation technique along with every online form?

Bellow is a basic javascript code to check that no form is submitted with empty fields:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<html>
<head>
<script Language="JavaScript"><!--
function Validator(Form)
{
 
  if (Form.UserName.value == "")
  {
    alert("Please enter a value for the \"User Name\" field.");
    Form.UserName.focus();
    return (false);
  }
 
  if (Form.Password.value == "")
  {
    alert("Please enter a value for the \"Password\" field.");
    Form.Password.focus();
    return (false);
  }
 
  if (Form.FullName.value == "")
  {
    alert("Please enter a value for the \"Full Name\" field.");
    Form.FullName.focus();
    return (false);
  }
  return (true);
}
//--></script>
</head>
 
<body>
<center>
<form name="Signup" action = "submit_form.php" method = "post" 
onsubmit="return Validator(this)" >
Username: <input type ="text"  name="UserName" size="20"> <b>-</b> 
Password: <input type ="text"  name="Password" size="20"> <b>-</b> 
Fullname: <input type ="text"  name="FullName" size="20"> <b>-</b> 
<input name="Submit" type="submit" value="Submit">
</form>
</center>
</body>
</html>

Leave a Reply

Haider’s WebSpace
Welcome to my technical blog. This is where I write, archive and share computer related articles. Subjects vary from posting technical solutions to researching particular topics. Feel free to comment and talk IT!
Sponsored Links
Posts Calendar
September 2010
M T W T F S S
« Feb    
 12345
6789101112
13141516171819
20212223242526
27282930