ASP 101 - Active Server Pages 101 - Web03
The Place ASP Developers Go!

Please visit our partners

Windows Technology Windows Technology
15 Seconds
ASP 101
ASP Wire
VB Forums
VB Wire
internet.commerce internet.commerce
Partners & Affiliates

ASP 101 is an site
ASP 101 is an site
Internet News
Small Business
Personal Technology

Corporate Info
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash

 Top ASP 101 Stories Top ASP 101 Stories
Getting Scripts to Run on a Schedule
The Top 10 ASP Links @
What is and Why Do I Need It?

Cache commonly used values in application variables
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates

Quick Tips

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.

If you know that visitors to your site will be using Internet Explorer 4.0, you can use VBScript on the client side to validate objects such as HTML form fields. Client-side VBScript is similar conceptually to JavaScript--it gets sent to the browser with the page's HTML and executes on the browser based on user events. If you want to support a broader reach of browsers, use JavaScript for your client-side scripting. A wide range of browsers, including both Navigator and Internet Explorer 4.0, support JavaScript.

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:

<META name="VI60_defaultClientScript" content="VBScript">
<META name="generator" content="Microsoft Visual Studio 6.0">
<SCRIPT id="clientEventHandlersVBS" language="vbscript">

Sub btnVerify_onclick
Dim EntryNumber
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.")
End If
MsgBox ("Please enter a numeric value.")
End if
End Sub


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> <HR>

<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"

<P> </P>

<P> </P></FONT></STRONG>


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.
Previous      Show All Tips      Next

If you have a tip you would like to submit, please send it to:

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback
The Network for Technology Professionals



Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers