I am writing an HTA and I need to pass a variable that I have in Javascript to a VBScript function. Can you please let me know how to do this? Here is a (nonworking) example of
If a function is defined in VBScript, it can be executed from JavaScript as if it were any other globally available function. Both scripting languages share global variables and functions. I used to use a function so that I could access MsgBox from my JavaScript code using the following:
The order of inclusion is important when mixing these scripts. If the first script on your page is vbscript, that becomes the default scripting engine for event handlers. If the first is javascript, that would be the default. Providing vbscript:
or javascript:
is a common misconception - in JavaScript a string followed by a colon indicates a label commonly paired with loops and break/continue statements. In VBScript, it would just cause an error. This confusion stems with the method of running script from a URL, e.g. in the href of an element:
do something
With your sample code, assuming closer
is a global variable then your event handler should look like this:
close
Also, take a look at this MSDN article on using JScript and VBScript on the same page.