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

Example 16.6:
Is it a Number?

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 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 } } } } //--> </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