We have read in the ‘Learn basics of the VBScript‘ that the VBScript can be used as client scripting( In Internet Explorer browser) as well as server scripting(IIS). In this article I’ll explain you how we can use the VbScript as client scripting.
You can use the script element to add VBScript code to an HTML page.Let’s suppose a simple html document. The following example uses a html input element of type button. For the click event of the this button example use the Button1_OnClick() procedure.
<html> <head> <title>Using VBScript in a html page</title> <script language="vbscript"> Sub Button1_OnClick() MsgBox "Welcome to AuthorCode" End Sub </script> </head> <body> <button id="Button1"> Click Me </button> </body> </html>
See the procedure name Button1_OnClick that contains the element id and event name separated with underscore(_).
Let’s see the another example to see that how to access the value of the input text type element. Make some small changes in above example like as:
<html> <head> <title>Using VBScript in a html page</title> <script language="vbscript"> Sub Button1_OnClick() MsgBox Text1.Value End Sub </script> </head> <body> <input type="text" id="Text1" /> <input type="button" id="Button1" value="Click Me" /> </body> </html>
In the example we access the entered text into the input text type control with the help of Value property. So it is the important to have some knowledge of the events and properties of the html elements. I am writing down the list of the few:
input element( type button)
Events: OnClick, OnFocus
Properties: Enabled, Name, Value
input element( type text)
Events: OnFocus, OnBlur, OnChange, OnSelect
Properties: Enabled, Name, Value,DefaultValue
input element(type radio)
Events: Click, Focus
Properties: Enabled, Name, Value, Checked
select element
Events: OnFocus, OnBlur, OnChange
Properties: Name, Length, Options, SelectedIndex
Exercise:
Add the above html elements in your web page and try to use their events and properties.
Next chapter:Use operators in VBScript
Previous chapter:Data types, Variables and Array in VBScript