What's wrong with this VBScript code? When I press on the button, the msgbox doesn't open

rey Source

What's wrong with this VBScript? When I press on the button, the msgbox doesn't open..

<script language="VBScript"> 

Sub showMsg 
    MsgBox "Hello";
End Sub


<button onclick="showMsg">Show Message</button> <p>


answered 3 years ago Dimitri #1

You haven't actually invoked the sub. Try <button onclick="showMsg()">

answered 3 years ago Steve #2

Check out this link .. Instead of calling the function from the button as you do in JS, its the name of the VB function's relation to the name of the button that matters.


Sub showMsg_OnClick
    MsgBox "Hello"
End Sub


<button name="showMsg">Show Message</button>

BUT also see this link VB Script is on its way out and may have limited functionality in current versions of IE and Win10's Edge.

If your environment is XP it might work, doesn't work for me but you are not looking at VB script unless to support legacy code.

EDIT: You can get the VB script code to work in IE if you go into developer tools (F12) and set the IE version to 10 or older.

comments powered by Disqus