Skip to content

Commit 92a4621

Browse files
committed
Finished Chapter 17 Exercise 2
1 parent 680e2df commit 92a4621

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

ch17exercise2.html

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<!DOCTYPE html>
2+
3+
<html lang="en">
4+
<head>
5+
<title>Chapter 17: Example 1</title>
6+
<style>
7+
.fieldname {
8+
text-align: right;
9+
}
10+
11+
.submit {
12+
text-align: right;
13+
}
14+
</style>
15+
</head>
16+
<body>
17+
<form id="whole">
18+
<table>
19+
<tr>
20+
<td class="fieldname">
21+
Username:
22+
</td>
23+
<td>
24+
<input type="text" id="username" />
25+
</td>
26+
</tr>
27+
<tr>
28+
<td class="fieldname">
29+
Email:
30+
</td>
31+
<td>
32+
<input type="text" id="email" />
33+
</td>
34+
</tr>
35+
<tr>
36+
<td class="fieldname">
37+
Password:
38+
</td>
39+
<td>
40+
<input type="text" id="password" />
41+
</td>
42+
<td />
43+
</tr>
44+
<tr>
45+
<td class="fieldname">
46+
Verify Password:
47+
</td>
48+
<td>
49+
<input type="text" id="password2" />
50+
</td>
51+
<td />
52+
</tr>
53+
<tr>
54+
<td colspan="2" class="submit">
55+
<input type="submit" value="Submit" id="Sub" />
56+
</td>
57+
<td />
58+
</tr>
59+
</table>
60+
</form>
61+
<script src="mootools-core-1.5.1-compressed.js"></script>
62+
<script>
63+
function checkUsername(e) {
64+
e.preventDefault();
65+
66+
var userValue = $("username").value;
67+
68+
if (!userValue) {
69+
alert("Please enter a user name to check!");
70+
return;
71+
}
72+
73+
var request = new Request.JSON({
74+
method: "get",
75+
data: {
76+
username: userValue
77+
},
78+
url: "ch14_formvalidator.php",
79+
onSuccess: checkEmail,
80+
onFailure: handleUsername
81+
}).send();
82+
}
83+
84+
function checkEmail(responseText, json) {
85+
alert(responseText.searchTerm + " is available!");
86+
87+
e.preventDefault();
88+
89+
var emailValue = $("email").value;
90+
91+
if (!emailValue) {
92+
alert("Please enter an email address to check!");
93+
return;
94+
}
95+
96+
var request = new Request.JSON({
97+
method: "get",
98+
data: {
99+
username: userValue
100+
},
101+
url: "ch14_formvalidator.php",
102+
onSuccess: handleEmail,
103+
onFailure: handleUsername
104+
}).send();
105+
}
106+
107+
function handleUsername(responseText, json) {
108+
alert("We're sorry, but " + responseText.searchTerm + " is not available.");
109+
}
110+
111+
function handleEmail(responseText, json) {
112+
if (responseText.available) {
113+
alert(response.searchTerm + " is available!");
114+
$("Sub").submit();
115+
} else {
116+
alert("We're sorry, but " + response.searchTerm + " is not available.");
117+
}
118+
}
119+
$("Sub").addEvent("click", checkUsername);
120+
</script>
121+
</body>
122+
123+
</html>

0 commit comments

Comments
 (0)