2

I've seen the related post on this, but it only covers using inline VBScript for onmouseover events, while calling a Javascript Function for the onClick.

Is there a way to call a VBScript Sub for the onClick event from a button that uses Javascript onmouseover and onmouseout events?

Currently when I try I get an error that the object does not support the property or method.

stefanB
  • 77,323
  • 27
  • 116
  • 141

3 Answers3

2

It is possible, but you will need to prefix all your script calls in HTML with the appropriate language.

onmouseover="javascript: vbfunction();"

If there are script calls that are not prefixed, you may get errors on the page as the parser doesn't know what scripting language is being used.

hova
  • 2,811
  • 20
  • 19
  • 1
    Internet Explorer defaults to the language of the first script element it parses. So if the first script element is javascript, you shouldn't need to specify "javascript:" in your event handler. – Andy E Jun 25 '09 at 14:29
  • Tried onclick="javascript: btnGet_Click();" (btnGet_Click is the name of the vb sub) and I still get the error that the object does not support this property or method. –  Jul 02 '09 at 15:58
  • You need to add it to all of your handlers. As the previous commenter noted, IE defaults to the first language, so if you specify it for all handlers, there are no ambiguities. – hova Jul 02 '09 at 17:46
  • Javascript is my first script element in the page, so per that comment, I should be able to remove the javascript: tag from the handler, since it should default to the language of the first script element (javascript, in my case). When I remove the javascript: tag from the handler, it still returns the "object does not support the property or method" error. Google can't fix my stupid. :( –  Jul 06 '09 at 20:03
  • Found the problem. My button ID was the same as the sub I was trying to call. –  Jul 06 '09 at 20:11
2

Put your code in the Head Tags: <head> </head>

Add your VBScript between these brackets:

<script type="text/vbscript">
</script>

Function myVBFunction()
    ' here comes your vbscript code
End Function

// From a hardcoded link, don't write a semicolon a the end:
<a href="#" onclick="VBscript:myVBFunction('parameter')">link</a> 

You can read more about it here.

bulevardi
  • 61
  • 1
0

Make sure that the name of the sub you're calling doesn't match the ID of any other object in the script.