Freelance Writing Jobs | Today's Articles | Sign In

 
Browse Sections

Events in VBScript


Visual Basic is an inherently graphical programming language. The way most information is retrieved and processed from the user is through graphical user interface objects that you create for your user. Once the GUI is in place, the user causes the functions and procedures within your program to be initiated through keystrokes or mouse clicks.

Depending on the types of objects control that you're using in your Web pages, you can write code that reacts to these types of messages. When dealing with the intrinsic controls though, the messages that you will deal with most often include mouse clicks, mouse movements, and keystrokes.

In the previous examples, the code was inserted into the body of HTML document, and it was executed automatically when the document was loaded.

<HTML>
<body>
<SCRIPT LANGUAGE="VBScript">
MsgBox "Document is loaded"
</SCRIPT>
</body> 
</HTML> 

For event driven procedures, the typical script is as follows:

<HTML>
<SCRIPT LANGUAGE="VBScript">
Sub btn1_onClick
MsgBox You clicked on me
End Sub
</SCRIPT>
<body>
<form>
<input type="button" name="btn1" value="Click Me">
</form>
</body> 
</HTML> 

The Sub procedure in the <SCRIPT> tags is an event procedure. There are two parts to the procedure name: the name of the button, btn1 (from the NAME attribute in the <INPUT> tag), and an event name, OnClick. The two names are joined by an underscore(_). Any time the button is clicked, Internet Explorer looks for and runs the corresponding event procedure, btn1_OnClick.

The copyright of the article Events in VBScript in VB Script is owned by Maxim Karetnikov. Permission to republish Events in VBScript in print or online must be granted by the author in writing.

Go To Page: 1 2

Articles in this Topic    Discussions in this Topic