Java Reference
In-Depth Information
Next, you get the value of the Username fi eld by using the $F() function and passing the string
username to it.
var userValue = $F(“username”);
Next, you use the responseText property of the XMLHttpRequest object to get the server applica-
tion's response and check to see if the user name is available.
if (request.responseText == “available”)
{
alert(“The username “ + userValue + “ is available!”);
}
else
{
alert(“We're sorry, but “ + userValue + “ is not available.”);
}
}
Based upon the outcome of the if statement, you tell the user either their desired user name is or isn't
available for them to use.
The checkEmail() function saw similar changes as checkUsername() .
function checkEmail()
{
var emailValue = $F(“email”);
if (emailValue == “”)
{
alert(“Please enter an email address to check!”);
return;
}
This code retrieves the value from the Email text box and determines if the user entered any informa-
tion into it. If they didn't, an alert box asks them to enter information and the function exits.
Next, go through the preparation steps for sending a request with Prototype. First create the parms
object.
var parms = new Object();
parms.email = emailValue;
You create an email property and assign it the value contained within the emailValue variable. Now
create the options object.
var options = getBasicOptions();
options.onSuccess = checkEmail_callBack;
options.parameters = parms;
You once again call the getBasicOptions() function to create the basic options for this request. Next,
you create and assign values for the onSuccess and parameters option properties.
Before the function exits, you perform the request by calling the Ajax.Request() constructor.
new Ajax.Request(“formvalidator.php”, options);
}
Search WWH ::




Custom Search