Step 3 - Handling Events

Internet Explorer User's Guide > Using Text Control with HTML and VBScript

If you are familiar with Visual Basic, then you should have no problem setting up event handlers in a web page. Event handlers are code that is called when a particular action is performed on or performed by a component. For example, let's say that you wish to perform an action whenever the user clicks on a field in the TX Text Control. You would setup an event handler for the FieldClicked event as follows:

<SCRIPT ID="EventHandlers" LANGUAGE="vbscript">
   Sub objTX_FieldClicked(ByVal FieldId)
      msgbox "A field has been clicked. Field identifier: " & FieldId
   End Sub

We recommend that script code that accesses components always be placed after the object tags of OCX components. But this is not necessary with event handler code as this code will not be called until a component is initialized.

Since Internet Explorer's VBScript does not support variable types, you cannot use variables such as Long, Boolean, Double, Integer, etc in your code. All variables in VBScript are Variants. Therefore, the following code would be incorrect and would generate a script error.

Sub objTX_FieldClicked(ByVal FieldId as Integer)

Use the following code instead, omitting any "as Integer" or other variable types...

Sub objTX_FieldClicked(ByVal FieldId)

Anyway, the parameter of the FieldClicked event can be easily accessed by VBScript, because it casts automatically the variable into the correct variable type.

The code shown here is contained in Step3.htm in the IE\HTML sample source directory.