VBScript tutorial lesson 2 adding VBScript code to HTML pages

Time:2022-5-23

VB tutorial > lesson 2 adding VBScript code to HTML pages
The script element is used to add VBScript code to an HTML page.

< script > tag

VBScript code is written between pairs of < script > tags. For example, the following code is a procedure to test the delivery date:

<SCRIPT LANGUAGE=”VBScript”>
<!–
Function CanDeliver(Dt)
CanDeliver = (CDate(Dt) – Now()) > 2
End Function
–>
</SCRIPT>

The beginning and end of the code are marked with < script >. The language property specifies the script language used. Since the browser can use multiple script languages, you must specify the script language used here. Note that the candeliver function is embedded in annotation tags (<! — and — >). This prevents browsers that do not recognize < script > tags from displaying code on the page.
Because the above example is a general function (independent of any form control), it can be included 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>

Script blocks can appear anywhere on the HTML page (in the body or head section). However, it is best to put all the general target script code in the head section so that all script code can be placed in a centralized way. This ensures that all script code is read and decoded before the body part calls the code.
A notable exception to the above rule is to provide internal code in a form in response to events of objects in the form. For example, the following example embeds script code in a form in response to a button click event in the form:

<HTML>
<HEAD>
< title > test button event < / Title >
</HEAD>
<BODY>
<FORM NAME=”Form1″>
Click < N1 “name =” input “> button
<SCRIPT FOR=”Button1″ EVENT=”onClick” LANGUAGE=”VBScript”>
Msgbox “button clicked!”
</SCRIPT>
</FORM>
</BODY>
</HTML>

Most script code is in a sub or function procedure and is executed only when other code wants to call it. However, VBScript code can also be placed outside the process, in script blocks. This type of code is executed only once when the HTML page is loaded. This allows you to initialize data or dynamically change the appearance of a web page when it is loaded.

Recommended Today

Python context manager content manager

In Python, we often hear about the context manager. Let’s discuss what it is and what its function is. In the context manager in Python, using with to open a file is the most used. After leaving the statements contained in with, some cleanup like operations will be performed, such as closing the file, closing […]