JavaScript: form validation directly at client

Close Index
 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<%@ Page language="c#" Codebehind="Question.aspx.cs" AutoEventWireup="false" Inherits="develop.Question" %>

<%@ Register TagPrefix="PageTop" TagName="MPageTop" Src="PageTop.ascx" %>
<%@ Register TagPrefix="PageBottom" TagName="MPageBottom" Src="PageBottom.ascx" %>


<PageTop:MPageTop runat="server" ID="PageTop" NAME="PageTop" />

<script language="javascript" type="text/javascript">

 function CheckForm(IForm)
 {
  if ((IForm.TEmail.value == '') && (IForm.tPhone.value == ''))
  {
    alert('You must complete either Email address or phone number');
    return false;
  }
  
  if (IForm.TEmail.value != '') 
  {
	if (IForm.TEmail.value.length > 5) 
		{
			EMailAddr = IForm.TEmail.value;
			if ((EMailAddr.indexOf ('@') < 1) || (EMailAddr.indexOf ('.') < 1))
			{ 
				alert ('Enter valid EMail address');				   
    			return false;
			}
		}
	else
		{ 
			alert ('You have very short EMail address');				   
    		return false;
		}
  }

  return true;
 } 
</script>


<form method="post" action="Question.aspx" onSubmit="return CheckForm(this);">
	<table border="0">
		<tr>
			<td width="150"><div id="FormDesc">I would like to know more about</div>
			</td>
			<td>&nbsp;</td>
			<td>
				<select name="cbReqType" size="1" id="FormInput">
					<option>Web Design</option>
					<option>Custom Programming</option>
					<option selected>General Info</option>
				</select><br>
				<input type="text" size="50" name="TInfoComm" value=".." id="FormInput">
			</td>
		</tr>
		<tr>
			<td colspan="3"><hr>
			</td>
		</tr>
		<tr>
			<td width="150"><div id="FormDesc">Please, Contact Me by Email</div>
			</td>
			<td>&nbsp;</td>
			<td>
				<input type="text" size="50"  maxlength="300" id="FormInput" name="TEmail">
			</td>
		</tr>
		<tr>
			<td><div id="FormDesc">or by Phone</div>
			</td>
			<td>&nbsp;</td>
			<td>
				<input type="text" size="20" name="tPhone" id="FormInput">
			</td>
		</tr>
		<tr>
			<td><div id="FormDesc">during the time</div>
			</td>
			<td>&nbsp;</td>
			<td>
				<input type="text" size="20" name="tTime" id="FormInput">
			</td>
		</tr>
		<tr>
			<td valign="top"><div id="FormDesc">Comment</div>
			</td>
			<td>&nbsp;</td>
			<td>
				<textarea name="tComment" rows="5" cols="40" id="FormInput">I would like to know more about</textarea>
				<br>
				<input type="submit" name="BSubmit" value="Submit Request" id="FormSubmitBtn">
			</td>
		</tr>
	</table>
	<PageBottom:MPageBottom runat="server" ID="MpageBottom" NAME="BottomTop" /></form>