Java Reference
In-Depth Information
else
{
alert(“We're sorry, but “ + userValue + “ is not available.”);
}
}
Other than the parameters, the only change to this function is the use of the val() method to retrieve
the textbox's value. Everything else remains the same; the function compares the data returned from
the server and displays a message to the user telling them the results of the user name query.
The changes to checkEmail() resemble those made to checkUsername().
function checkEmail()
{
var emailValue = $(“#email”).val();
if (emailValue == “”)
{
alert(“Please enter an email address to check!”);
return;
}
var parms = new Object();
parms.email = emailValue;
$.get(“formvalidator.php”, parms, checkEmail_callBack);
}
You use the jQuery function to select the Email text box and retrieve its value with the val() method.
You then determine if the user entered data, and ask them to do so if they didn't. Next, you create the
parms object, create and assign a value to the email property, and make the request with the $.get()
method.
On a successful request, the checkEmail_callBack() function executes, and the changes to this func-
tion mirror that of checkUsername_callBack().
function checkEmail_callBack(data, status)
{
var emailValue = $(“#email”).val();
if (data == “available”)
{
alert(“The email “ + emailValue + “ is currently not in use!”);
}
else
{
alert(“I'm sorry, but “ + emailValue + “ is in use by another user.”);
}
}
In case an Ajax error occurs, you register an Ajax event handler for the ajaxError event. The event
handler function is called ajax_error() , and it displays an error message to the user. Its defi nition
follows:
function ajax_error(event, request, settings)
{
Search WWH ::




Custom Search