| home / experts / dhtml / column22 |
|

As you know, or can easily guess, to include VBScript in our page, we enclose it in the SCRIPT tag with a LANGUAGE attribute value of "VBScript":
<SCRIPT LANGUAGE="VBScript" TYPE="text/vbscript"> <!-- ' VB statements go here --> </SCRIPT>
Already, you should have noticed two differences from the JavaScript standard:
The new HTML4 standard foresees the use of multiple scripting languages in a single page. Since scripts can exist outside of the SCRIPT tag, as in the case of event handlers, the LANGUAGE attribute can be used in any tag to denote the script language used. For example:
<A HREF="somelink.html" LANGUAGE="JavaScript"
onClick="jsFunction()">Execute JS</A>
<A HREF="somelink.html" LANGUAGE="VBScript"
onClick="vbFunction()">Execute VB</A>
Navigator does not support VBScript, nor does it support the LANGUAGE attribute in tags other than SCRIPT. It is, therefore, not advisable to use VBScript outside of the SCRIPT tag. As we will see further on, JavaScript can be used to call a VBScript function, allowing both browsers to co-exist.
Explorer recognizes both languages, but considers JavaScript to be the default scripting language. The default language, however, is automatically changed to reflect the first language used on a page.
Example1:
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<-- JS established as default
...
</SCRIPT>
<SCRIPT LANGUAGE="VBScript">
<-- LANGUAGE attribute makes VBScript kick in;
overrides default
...
</SCRIPT>
<SCRIPT>
<-- LANGUAGE attribute omitted;
identified as JS (default)
...
</SCRIPT>
</HEAD>
<BODY>
<A HREF="somelink.html" onClick="jsFunction()">Execute JS</A>
<-- LANGUAGE attribute omitted;
identified as JS (default)
<A HREF="somelink.html" LANGUAGE="VBScript" onClick="vbFunction()">Execute JS</A>
<-- LANGUAGE attribute overrides default;
</BODY>
</HTML>
Example2:
<HTML>
<HEAD>
<SCRIPT LANGUAGE="VBScript">
<-- VB established as default
...
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
<-- LANGUAGE attribute makes JavaScript kick in;
overrides default
...
</SCRIPT>
<SCRIPT>
<-- LANGUAGE attribute omitted;
identified as VB (default)
...
</SCRIPT>
</HEAD>
<BODY>
<A HREF="somelink.html" LANGUAGE="JavaScript
onClick="someFunction()">Execute JS</A>
<-- LANGUAGE attribute overrides default;
<A HREF="somelink.html"
onClick="someFunction()">Execute JS</A>
<-- LANGUAGE attribute omitted; identified as JS (default)
</BODY>
</HTML>
These three pointers will allow us to selectively use VBScript in a cross-browser page.
It's time to create our first VBScript function.
Produced by Peter Belesis and
All Rights Reserved. Legal Notices.
Created: Nov. 18, 1998
Revised: Nov. 18, 1998
URL: http://www.webreference.com/dhtml/column22/js-vbTags.html