Java Reference
In-Depth Information
oHttp.async = false;
oHttp.send();
You now have an Ajax module that requests information in both asynchronous and synchronous
communication!
Exercise 2 Question
It was mentioned earlier in the chapter that the smart forms could be modifi ed to not use hyperlinks.
Change the form that uses the HttpRequest module so that the user name and e-mail fi elds are checked
when the user submits the form. Use the form's onsubmit event handler and cancel the submission if a
user name or e-mail is taken. Also use the updated HttpRequest module from Question 1 and use syn-
chronous requests. The only time you need to alert the user is when the user name or e-mail is taken, so
make sure to return true if the user name and e-mail pass muster.
Exercise 2 Solution
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN”
“http://www.w3.org/TR/html4/strict.dtd”>
<html>
<head>
<title>Form Field Validation</title>
<style type=”text/css”>
.fieldname
{
text-align: right;
}
.submit
{
text-align: right;
}
</style>
<script type=”text/javascript” src=”HttpRequest.js”></script>
<script type=”text/javascript”>
var isUsernameTaken;
var isEmailTaken;
function checkUsername_callBack(sResponseText)
{
if (sResponseText == “available”)
{
isUsernameTaken = false;
}
else
{
isUsernameTaken = true;
}
}
function checkEmail_callBack(sResponseText)
{
Search WWH ::




Custom Search