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

Please visit our partners


Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates














ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
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 @ Microsoft.com
What is Adovbs.inc and Why Do I Need It?

QUICK TIP:
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:

<HTML>
<HEAD>
<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.")
Else
MsgBox ("Your entry was valid.")
End If
Else
MsgBox ("Please enter a numeric value.")
End if
End Sub

-->
</SCRIPT>
</HEAD>

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:

<BODY>
<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"
value="Verify"></FONT></P>

<P> </P>

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

</BODY>
</HTML>

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: webmaster@asp101.com.


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

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