Use client-side validation
A client-side script is a script that is included in a page's HTML and is executed on the client based on user events. Using a client-side script means the browser doesn't have to make a round-trip to the server to perform routine client-side tasks. For example, you wouldn't want to send the browser to the server to validate that all of the required fields on a form were filled out.
Suppose you wanted to verify that a user entered a number between 1 and 10. You can create a client VBScript that will run whenever the user attempts to submit the form data:
EntryNumber = window.txtNumber.value
if IsNumeric(EntryNumber) then
if EntryNumber < 1 or EntryNumber > 10 then
MsgBox ("Please enter a number between 1 and 10.")
MsgBox ("Your entry was valid.")
MsgBox ("Please enter a numeric value.")
This single VBScript subroutine is called btnVerify_onclick. If you've ever programmed in Visual Basic, you'll recognize this as the onClick event-handler for the btnVerify object. The other object used in this routine is the window.txtNumber object, which holds the value we're verifying. Both btnVerify and txtNumber are defined as part of the form in the body of our sample HTML page:
<P><STRONG><FONT size=6>Validating User Input</FONT></STRONG></P><STRONG><FONT size=6>
<P><FONT size="3">Enter a value between
1 and 10:
<INPUT id="txtNumber" name="txtNumber" style="height: 22px; width: 39px" value="15"> <INPUT id="btnVerify" name="btnVerify" style="height: 24px; width: 56px" type="button" value="Verify"></FONT></P>
When the user clicks the Verify button, the browser will run the btnVerify_onclick handler to check the number. For this example, we've inserted 15 into the txtNumber field so that just by clicking the Verify button you can generate the error message. Remember, this client-side VBScript works only with IE 3.0 and higher.