Java Reference
In-Depth Information
On a successful request, the Prototype Ajax component calls checkEmail_callBack() and passes it
the XMLHttpRequest object used to make the request to the server.
function checkEmail_callBack(request)
{
var emailValue = $F(“email”);
if (request.responseText == “available”)
{
alert(“The email “ + emailValue + “ is currently not in use!”);
}
else
{
alert(“I'm sorry, but “ + emailValue + “ is in use by another user.”);
}
}
You fi rst get the value of the Email text box and store it in the emailValue variable. Next, you deter-
mine if the e-mail is available for the user to use by comparing the request's responseText property
with the string “available” . You then display a message to the user, telling them their e-mail is or
isn't available, based upon the result of the if statement.
Prototype is a powerful framework that provides a rich set of utilities to change the way you write
JavaScript. Like jQuery, a simple section such as this is far too small to cover the framework adequately.
For further information on Prototype and the utility it offers, see the API documentation at http://
www.prototypejs.org/api and the tutorials at http://www.prototypejs.org/learn .
Delving into MooTools
At fi rst glance, MooTools looks identical to Prototype, and rightly so. MooTools was fi rst developed to
work with Prototype, so it shouldn't be surprising to see some of the utility provided by MooTools is
almost identical to that of Prototype.
However, MooTools is more of a cross between jQuery and Prototype as far as DOM manipulation is
concerned. Like Prototype, MooTools' goal is to augment the way you write JavaScript, providing tools
to write classes and inherit from them. Also like Prototype, MooTools adds in a rich set of extensions to
make DOM manipulation easier, and you'll fi nd that selecting DOM objects in MooTools is exactly the
same as Prototype. But as you'll see in the following sections, the extension method names and the way
in which you use them is reminiscent of jQuery.
Finding Elements
When testing your MooTools installation, you saw the dollar function used, and you learned that it was
similar to Prototypes. Well, let's clear it up now; they are exactly the same. They fi nd the element and
extend it, albeit with different methods that you'll see in the following sections.
$(“myDiv”)
Search WWH ::




Custom Search