Java Reference
In-Depth Information
Note
Hiding an iframe through CSS enables you to easily show it if you
need to debug the server‐side application.
Next up, the JavaScript:
function checkUsername(e) {
e.preventDefault();
var userValue = document.getElementById("username").value;
if (!userValue) {
alert("Please enter a user name to check!");
return;
}
var url = "ch14_iframevalidator.php?username=" + userValue;
frames["hiddenFrame"].location = url;
}
This
checkUsername()
function is almost identical to Example 1. The value of the
url
variable is
changed to the new
ch14 _ iframvalidator.php
file. The actual request is made by accessing the
<iframe/>
element using the
frames
collection and setting its
location
property to the new URL.
The
checkEmail()
function has the same modifications:
function checkEmail(e) {
e.preventDefault();
var emailValue = document.getElementById("email").value;
if (!emailValue) {
alert("Please enter an email address to check!");
return;
}
var url = "ch14_iframevalidator.php?email=" + emailValue;
frames["hiddenFrame"].location = url;
}
As before, the
checkEmail()
function retrieves the text box's value and checks to see if the user entered
data. It then constructs the URL using
ch14 _ iframevalidator.php
and loads the URL into the
<iframe/>
.
Dealing with Delays
The web browser is just like any other conventional application in that user interface (UI) cues tell
the user that something is going on. For example, when a user clicks a link, the throbber animation
may run or the cursor might change to display a “busy” animation.