VBScript Basics Tutorial Two add VBScript code to an HTML page

Source: Internet
Author: User
Tags html page
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.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.