Previous Example-|-Next Chapter's Examples-|-Return to Chapter Listing
Example 16.8:
Not Too Long, Nor Too Short
This is supposed to be a 3-digit number, but type something longer, then try something shorter:
Now click on this button in the second form:
You'll see the text in the third form:
This is the script we used. In the HEAD...
function Length() {
var sCheck = document.fred.elements[0].value
if (sCheck.length > 3 || sCheck.length < 3) {
alert("You must type 3 characters: no more, no less")
}
else {
Pass()
}
}
function Pass() {
var sCheck = document.fred.elements[0].value
nCheck = parseInt(sCheck, 10)
if (nCheck <=99 || nCheck == 0) {
alert("This is not a 3-digit number.")
}
else {
if (nCheck >= 100) {
if (nCheck >=201) {
alert("You entered a number that's too high. You must enter a number within the range of 100 to 200 inclusive.")
}
else {
document.joe.elements[0].value = nCheck }
}
}
}
//-->
Then these forms:
Now click on this button in the second form:
You'll see the text in the third form:
Also, at the bottom of the form we moved focus to the text box with this:
Previous Example-|-Next Chapter's Examples-|-Return to Chapter Listing