Events in VBScript

0 Comments

Written by Jason Davies Topics:

A different event is triggered for each object on a Web page when certain things happen. e.g. the mouse is moved or clicked, or the page is loaded. There are many different events for various objects. Since VBScript is an event-driven language, everything operates by events. There are a few ways for specifying what happens in a script when an event occurs. The following explains the syntax of three ways for specifying what happens when a certain event is triggered:

Attributes

You can specify an event as an attribute of a tag for an object or control on a page. The value of this attribute should be a subroutine which you have already defined inside a script tag. Remember that the language attribute must be included in the tag for the object. The general syntax is:

<... eventname="method" language="VBScript" ...>

where eventName is any valid event for the corresponding object or control and method is the name of the subroutine that you want to execute when the event occurs.

Script Tags

Using the attributes for the script tag you can specify what event of what object to use the enclosed code for. This is useful if you have multiple subroutines or statements outside of subroutines that need to exist in your script. The syntax for doing this is:

<script language="VBScript" for="ObjectName" event="EventName">
...
</script>

The for attribute is used to specify the name of the object to use the code for, and the event attribute specifies which event causes the code to be invoked.

Subroutines

This may well be the simplest method of triggering an event and executing some code after the event has occured. This method uses a method with the same name as the object or control you intend to use followed by an underscore and then the name of the event. The general syntax is:

<script language="VBScript">
...
sub ObjectName_ObjectEvent
...
end sub
...
</script>

0 Responses to “Events in VBScript”

Leave a Comment

:
: