Java Reference
In-Depth Information
<td class=”fieldname”>
Verify Password:
</td>
<td>
<input type=”text” id=”password2” />
</td>
<td />
</tr>
<tr>
<td colspan=”2” class=”submit”>
<input type=”submit” value=”Submit” />
</td>
<td />
</tr>
</table>
</form>
</body>
</html>
Save this as ch15_examp6.htm in your web server's root directory, as this fi le must be hosted on a web
server in order to work correctly. Point your browser to http://youserver/ch15_examp6.htm and
test out the form.
This page works exactly like ch15_examp4.htm (the jQuery version) and the original validate_form
.htm, but quite a few changes were made to this version. The fi rst major change is the addition of two
new functions called getBasicOptions() and request_onfailure().
The purpose of the fi rst function is to create an object containing the basic options needed for the
Ajax.Request() constructor to check the user name and e-mail the user wants to use.
function getBasicOptions()
{
var options = new Object();
options.method = “get”;
options.onFailure = request_onfailure;
return options;
}
This function fi rst creates an object called options. You then add a method property and assign it a
value containing the string “get”.
Next, you add another property, called onFailure , and assign a pointer to the request_onfailure()
function to it. You return the options object to the caller, thus creating the basic options for the
Ajax.Request() constructor. This function is primarily for convenience; instead of having to type
these lines of code twice (one in checkUsername() and one in checkEmail() ), you simply have to
type it once here and call this function to return these options.
The second new function, request_onfailure(), is used for both the user name and e-mail check
requests. If the request fails for some reason, the request_onfailure() function executes.
function request_onfailure(request)
{
alert(“An error occurred. HTTP Status Code: “ + request.status);
}
Search WWH ::




Custom Search