Vbscript| Basic Tutorials | page
The SCRIPT element is used to add VBScript code to an HTML page.
<SCRIPT> Mark
The VBScript code is written between pairs <SCRIPT> tags. For example, the following code is the process of passing a date for a test:
<script language= "VBScript" >
<!--
Function Candeliver (Dt)
Candeliver = (CDate (Dt)-now ()) > 2
End Function
-->
</SCRIPT>
The start and end parts of the code have <SCRIPT> tags. The LANGUAGE property is used to specify the Script language to use. Because browsers can use a variety of script languages, you must specify the script language used here. Note that the Candeliver function is embedded in the annotation tags (<!--and-->). This prevents browsers that do not recognize <SCRIPT> markup from displaying the code in the page.
Because the above example is a common function (not dependent on any form control), you can include it in the Head section of the page:
<HTML>
<HEAD>
<TITLE> Order </TITLE>
<script language= "VBScript" >
<!--
Function Candeliver (Dt)
Candeliver = (CDate (Dt)-now ()) > 2
End Function
-->
</SCRIPT>
</HEAD>
<BODY>
...
A SCRIPT block can appear anywhere on an HTML page (in the body or head section). However, it is a good idea to put all the generic target script codes in the Head section so that all the script code is placed centrally. This ensures that all Script code is read and decoded before the body section invokes the code.
A notable exception to the above rules is that the internal code is provided in the form in response to the events of the objects in the form. For example, the following example embeds a Script code in a form in response to a click event for a button in a form:
<HTML>
<HEAD>
<TITLE> Test Button Events </TITLE>
</HEAD>
<BODY>
<form name= "Form1" >
<input type= "button" Name= "Button1" value= "click" >
<script for= "Button1" event= "OnClick" language= "VBScript" >
The MsgBox button is clicked! "
</SCRIPT>
</FORM>
</BODY>
</HTML>
Most Script code executes in a Sub or Function procedure only when other code calls it. However, you can also place VBScript code outside of a procedure, in a SCRIPT block. This type of code executes only once when the HTML page is loaded. This allows you to initialize data or dynamically change the appearance of the page when you load a Web page.