A simple page
Use Microsoft? Internet Explorer allows you to view the pages created with the following HTML code. If you click the button on the page, you can see the running result of VBScript.
<HTML>
<HEAD> <TITLE> A simple homepage </TITLE>
<Script language = "VBScript">
<! --
Sub Button1_nClick
MsgBox "Mirabile visu ."
End Sub
-->
</SCRIPT>
</HEAD>
<BODY>
<H3> A simple homepage </H3> <HR>
<FORM> <input name = "Button1" TYPE = "BUTTON" VALUE = "Click here"> </FORM>
</BODY>
</HTML>
The result is a bit simple: a dialog box displays a Latin phrase (meaning "looks pretty "). However, this Code actually does many things.
When Internet Explorer reads the page, it finds the <SCRIPT> mark to identify the VBScript code and save the code. When you click the button, Internet Explorer connects the button to the code and runs the process.
<SCRIPT> the Sub process in the tag is an event process. The process NAME consists of two parts: one part is the button NAME, that is, Button1 (obtained from the NAME attribute in the <INPUT> tag), and the other part is the event NAME, that is, nClick. The two parts are connected by underscores. When you click the button, Internet Explorer searches for and runs the corresponding event process, that is, Button1_nClick.
Internet Explorer defines events that can be used for Form Controls in the Internet Explorer Scripting Object Model document.
You can also use a combination of controls and processes on the page. VBScript and the form display some simple interactions between controls.
Other methods for appending code to an event
The above method may be the simplest and most commonly used, but you can also use the other two methods to attach VBScript code to the event. One way is to add shorter internal code to the tag of the definition control. For example, when you click the button, the following <INPUT> MARK performs the same operation as the previous example:
<Input name = "Button1" TYPE = "BUTTON"
VALUE = "Click here" nClick = 'msgbox "Mirabile visu." '>
Note that function calls are included in single quotes, and MsgBox function strings are included in double quotes. Multiple statements can be used as long as the statement is separated by a colon.
Another way is to specify specific controls and events in the <SCRIPT> tag:
<Script language = "VBScript" EVENT = "nClick" FOR = "Button1">
<! --
MsgBox "Mirabile visu ."
-->
</SCRIPT>
Because the <SCRIPT> tag specifies events and controls, you do not need to use Sub and End Sub statements.