Dynamic HTML, Data Binding, and ActiveX Controls

Although client-side scripting adds flexibility to standard HTML, it is used for little more than validating data in a form prior to submission. The limitation of scripting lies in the very nature of HTML itself: HTML is a streaming language. That means that HTML actually enters the browser one character at a time and the Web page is built by the browser as the data stream enters the client. Once the data has finished entering the browser, the stream is closed; and once the stream is closed, the HTML page cannot be changed.

A browser can, to a limited degree, modify the HTML stream while it is actually entering the browser. Microsoft Internet Explorer's Document object supports a method named Write, which allows VBScript code to modify the HTML stream. Because this stream modification must occur while the page is loading, you must create your VBScript code outside the boundaries of a procedure. When code is executed outside a procedure, the code runs immediately when the page is loaded—a technique appropriately called immediate execution. The following code uses immediate execution to add HTML content to the stream:

<SCRIPT LANGUAGE="VBScript"> <!--     Document.Write "<H1>New HTML Content</H1>" --> </SCRIPT> 

Notice that the code is written directly under the SCRIPT section and is not enclosed in any Sub or Function procedure. This is the key to immediate execution. Remember that if the page is fully loaded, the stream is closed and cannot be modified.

As an example, consider a Web site that offers books for sale. You want this site to present a new special offer to customers each month. In order to change the special, you can use the Write method of the Document object. Use the VBScript Now function to get the current date, and then apply the Month function to determine the month. Specials can be displayed using the Write method based on the month. Listing 4-1 contains the complete code for this exercise.

Listing 4-1. Immediate execution.


 <HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft Developer Studio"> <META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1"> <TITLE>Immediate Execution</TITLE> </HEAD> <BODY> <H1>Here's the monthly special</H1><P> <SCRIPT LANGUAGE="VBScript"> <!--     Dim strSpecial     ' Pick a special based on the month of the year     Select Case Month(Now)         Case 1             strSpecial = "dBASE III: A Practical Guide"         Case 2             strSpecial = "The dBASE Programming Language"         Case 3             strSpecial = "dBASE III Plus"         Case 4             strSpecial = "Database Management: Developing Application "             strSpecial = strSpecial & "Systems Using Oracle"         Case 5             strSpecial = "Wordstar 4.0-6.0 Quick Reference Guide"         Case 6             strSpecial = "Oracle Triggers and Stored Procedure "             strSpecial = strSpecial & "Programming"         Case 7             strSpecial = "Programming in Clipper"         Case 8             strSpecial = "Inside Macintosh"         Case 9             strSpecial = "Omni Online Database Directory"         Case 10             strSpecial = "Structured C for Engineering and Technology/"             strSpecial = strSpecial & "Book and Disk"         Case 11             strSpecial = "An Introduction to Assembly Language "             strSpecial = strSpecial & "Programming for the Intel "             strSpecial = strSpecial & "8088 Microprocessor"         Case 12             strSpecial = "Applied Calculus with Linear Programming: "             strSpecial = strSpecial & "For Business, Economics, Life "             strSpecial = strSpecial & "Sciences, and Social Sciences"     End Select     Document.Write "<H4>" & strSpecial & "</H4>" --> </SCRIPT> </BODY> </HTML> 



Programming Active Server Pages
Programming Active Server Pages (Microsoft Programming Series)
ISBN: 1572317000
EAN: 2147483647
Year: 1996
Pages: 84

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net