Previous Example-|-Next Example-|-Return to Chapter Listing

Example 16.5:
Verifying That a Number is Within a Range

Type a 3-digit number into the text box:

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... <SCRIPT LANGUAGE="JAVASCRIPT"> <!-- function Pass() { var nCheck = document.fred.elements[0].value 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 = document.fred.elements[0].value } } else { alert("You entered a number that's too low. You must enter a number within the range of 100 to 200 inclusive.") } } //--> </SCRIPT> Then these forms: <FORM NAME="fred"> <input type="text" size="3"><P> </FORM> <I>Now click on this button in the second form:</I> <FORM> <input type="button" value="Check the Text and Pass if Between 100 and 200" onclick="Pass()"> </FORM> <I>You'll see the text in the third form:</I> <FORM NAME="joe"> <input type="text" size="30"><P> </FORM> Also, at the bottom of the form we moved focus to the text box with this: <SCRIPT LANGUAGE="JAVASCRIPT"> <!-- document.fred.elements[0].focus() //--> </SCRIPT>
Previous Example-|-Next Example-|-Return to Chapter Listing