VB tutorial> Lesson 2 add VBscript code to the HTML page
The SCRIPT element is used to add VBScript code to the HTML page.
<SCRIPT> MARK
VBScript code is written in pairs between <SCRIPT> tags. For example, the following code is a test transfer date process:
<Script language = "VBScript">
<! --
Function CanDeliver (Dt)
CanDeliver = (CDate (Dt)-Now ()> 2
End Function
-->
</SCRIPT>
The start and end parts of the Code are marked with <SCRIPT>. The LANGUAGE attribute is used to specify the Script LANGUAGE used. Because the browser can use multiple Script languages, you must specify the Script language used here. Note that the CanDeliver function is embedded in the annotation mark (<! -- And -->. This prevents the browser that cannot recognize the <SCRIPT> flag from displaying the code on the page.
Because the above example is a general function (not dependent on any form control), you can include it in the HEAD part of the page:
<HTML>
<HEAD>
<TITLE> order </TITLE>
<Script language = "VBScript">
<! --
Function CanDeliver (Dt)
CanDeliver = (CDate (Dt)-Now ()> 2
End Function
-->
</SCRIPT>
</HEAD>
<BODY>
...
The SCRIPT block can appear anywhere on the HTML page (in the BODY or HEAD part ). However, it is best to place all the general target Script code in the HEAD part so that all the Script code can be placed in a centralized manner. This ensures that all Script code is read and decoded before the BODY part calls the code.
An exception to the preceding rule is that internal code is provided in the form to respond to events of objects in the form. For example, the following example embeds Script code in the form to respond to the button clicking event in the form:
<HTML>
<HEAD>
<TITLE> test button event </TITLE>
</HEAD>
<BODY>
<Form name = "Form1">
<Input type = "Button" NAME = "Button1" VALUE = "click">
<Script for = "Button1" EVENT = "nClick" LANGUAGE = "VBScript">
The MsgBox button is clicked! "
</SCRIPT>
</FORM>
</BODY>
</HTML>
Most Script code is executed only when other code calls Sub or Function. However, you can also place the VBScript code outside the process and in the SCRIPT block. This type of code is executed only once when an HTML page is loaded. In this way, you can initialize the data or dynamically change the appearance of the page when loading the Web page.