Java Reference
In-Depth Information
Exercise 2 Question
Modify the answer to Chapter 14's Question 2 using Prototype. Also add error reporting for when an
error occurs with the Ajax request.
Exercise 2 Solution
As with the answer to Question 1, synchronous communication is key to the script working correctly, so
add it to the request options. The highlighted lines make Prototype work with this script.
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN”
“http://www.w3.org/TR/html4/strict.dtd”>
<html>
<head>
<title>Chapter 15: Question 2 Answer with Prototype</title>
<style type=”text/css”>
.fieldname
{
text-align: right;
}
.submit
{
text-align: right;
}
</style>
<script type=”text/javascript” src=”prototype-1.6.0.3.js”></script>
<script type=”text/javascript”>
var isUsernameTaken;
var isEmailTaken;
function checkUsername_callBack(request)
{
if (request.responseText == “available”)
{
isUsernameTaken = false;
}
else
{
isUsernameTaken = true;
}
}
function checkEmail_callBack(request)
{
if (request.responseText == “available”)
{
isEmailTaken = false;
}
else
{
isEmailTaken = true;
Search WWH ::




Custom Search