-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreturning error string.html
88 lines (83 loc) · 2.67 KB
/
returning error string.html
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
<html>
<head>
<title>CS 164 Form Field Verification Example</title>
<script language='javascript'>
function check(form)
{
//Stevie Parris
var str = form.lastName.value
var result = "str=" + str + "\n"
+ "str.substring(5,7)=" + str.substring(5,7) + "\n"
form.DebuggingArea.value = result
}
function ErrorAlert(field, description)
{
result = 'The field ' + field + ' ' + description + "\n"
return(result);
}
function errorCheck(form)
{
if(form.lastName.value == "")
result = ErrorAlert("lastName", "must not be left blank.")
if(form.firstName.value == "")
result = result + ErrorAlert("firstName", "must not be left blank.")
if(form.emailAddress.value == "")
result = result + ErrorAlert("emailAddress", "must not be left blank.")
if(form.emailAddress.value.indexOf('@') == -1)
result = result + ErrorAlert("emailAddress", "must include '@' symbol.")
if(form.dateOfBirth.value.length < 10 || form.dateOfBirth.value.length > 10 || form.dateOfBirth.value.substr(2,1) != '/' || form.dateOfBirth.value.substr(5,1) != '/')
result = result + ErrorAlert("dateOfBirth", "should be in the format mm/dd/yyyy.")
alert(result)
}
</script>
</head>
<body>
<table WIDTH="100%" BORDER="0" CELLPADDING="8" BGCOLOR="#000066">
<tr>
<td><h1><font COLOR="#FFCC66">Form Field Verifier</font> </h1></td>
</tr>
</table>
<p><i>You are to modify this form so that the values submitted by the user are
verified for correctness.</i></p>
<table BORDER="0" CELLPADDING="8" BORDERCOLOR="#CC0000" BGCOLOR="#FFCC66">
<tr>
<td> <form NAME="userdata">
<p> </p>
<p><b>First Name: </b>
<input NAME="firstName" TYPE="text" SIZE="35" />
<b>Middle Initial:</b>
<input NAME="middleInitial" TYPE="text" SIZE="5" MAXLENGTH="1" />
<b>Last Name:</b>
<input NAME="lastName" TYPE="text" SIZE="35" />
</p>
<p><b>Email Address: </b>
<input NAME="emailAddress" TYPE="text" SIZE="80" />
</p>
<p><b>Date of Birth:</b>
<input TYPE="text" NAME="dateOfBirth" />
</p>
<p>
<input TYPE="button" onClick="errorCheck(form)" VALUE="Submit" />
<input TYPE="reset" NAME="reset" VALUE="Reset" />
</p>
<p> </p>
<p><b>DEBUGGING:</b>
<textarea NAME="DebuggingArea" COLS="80" ROWS="10"></textarea>
</p>
<p> </p>
</form></td>
</tr>
</table>
<p> </p>
<p><b>Notes:</b> </p>
<p>Use the <b>DEBUGGING</b> area to view values as follows:</p>
<table BORDER="1" CELLPADDING="10" CELLSPACING="0" BORDERCOLOR="#000066" BGCOLOR="#FFFF99">
<tr>
<td>
<pre>
</pre>
</td>
</tr>
</table>
</body>
</html>