Java Reference
In-Depth Information
return;
}
checkEmail();
}
This function takes the response and parses it into a JavaScript object. If the username is not
available, it displays the error message to the user and returns. Nothing else is processed when the
username is unavailable, but if it is available, it calls checkEmail() :
function checkEmail() {
var emailValue = document.getElementById("email").value;
if (!emailValue) {
alert("Please enter an email address to check!");
return;
}
var url = "ch14_formvalidator.php?email=" + emailValue;
var request = new HttpRequest(url, handleEmailResponse);
request.send();
}
This function is also largely the same. The only difference is the callback function passed to the
HttpRequest constructor; it's called handleEmailResponse() . It parses the request, and it is the last
step in the process:
function handleEmailResponse(responseText) {
var response = JSON.parse(responseText);
if (!response.available) {
alert("The email address " + response.searchTerm +
" is unavailable. Try another.");
return;
}
document.theForm.submit();
}
Once again, if the e‐mail address is not available, this function displays the error message to the user
and returns. But if the e‐mail address is available, the form is finally submitted.
Chapter 15
exercise 1 Question
Being able to control playback is cool, but your custom UI needs to also control volume. Add an
<input type="range" /> element to Example 3 to control the volume. Remember that the range of
Search WWH ::




Custom Search