When I am developing new script, I usually use VBScript (or powershell but that’s another story).
but sometimes I already have some old functions written in JScript, that I need to use in my VBScript.
This is often if I am creating a HTA.
This code example shows how to use both languages in HTA:
<html> <head> <title>Untitled</title> <script language="VBScript"> <!-- Sub vbMessage() ' Here's a client-side VBScript. It will display a message box. MsgBox "This message box was called from a VBScript function." End Sub //--> </script> <script language="JavaScript" type="text/javascript"> <!-- function jsMessage() { /* This is client-side javascript. It will display a message box. */ alert('This message box was called from a Javascript function.'); /* Now see if we can call a VBScript function... */ vbMessage() ; } //--> </script> </head> <body> <form name="frmTest"> <input type="button" value="Test Two Scripts!" onclick="javascript:jsMessage();" /> </form> </body> </html>
Notice that the onclick on the button does not call
onclick = “jsMessage();”
but instead we call it by
onclick = “javascript:jsMessage();”
This tells the script to use the js function instead of the vbscript function.
therefore you have full control, even if both VBscript and JScript contains a function by the same name.
Good day..
When I run this code, I get an error after the JavaScript portion displays its alert….
what would cause the following error? what is needed to address it?
Uncaught ReferenceError: vbMessage is not defined
at jsMessage
at HTMLInputElement.onclick