Wednesday, August 6, 2008

Adding VBScript Code to an HTML Page

You can use the SCRIPT element to add VBScript code to an HTML page.
The
Beginning and ending


...
You can use SCRIPT blocks anywhere in an HTML page. You can put them in both the BODY and HEAD sections. However, you'll probably want to put all general-purpose scripting code in the HEAD section in order to keep all the code together. Keeping your code in the HEAD section ensures that all code is read and decoded before it's needed by any calls from within the BODY section.

One notable exception to this rule is that you may want to provide inline scripting code within forms to respond to the events of objects in your form. For example, you can embed scripting code to respond to a button click in a form:





Test Button Events








Most of your code will appear in either Sub or Function procedures and will be called only when code you have written causes it to execute. However, you can write VBScript code outside procedures, but still within a SCRIPT block. This code is executed only once, when the HTML page loads. This allows you to initialize data or dynamically change the look of your Web page when it loads.