0

I am authoring a number of HTML files that will be rendered by an IE control embedded in a third-party application.

In order to provide some fairly complex UI elements with the least amount of fuss, I elected to do most of my coding in JavaScript with jQuery. This generally works well, however the host application provides a large library of support functions I will need to call in order to trigger certain actions (such as printing and database updates). These support functions are all in external VBScript (.vbs) files that I can include in the HTML files' header.

Calling the VBscript functions and accessing global variables from within my JavaScript functions works flawlessly when done directly, but I can't figure out how to pass a reference to a function that was defined in VBScript to a jQuery event handler.

For example, the following code:

 1: <script type="text/vbscript">
 2:   Function handleClick
 3:      MsgBox "Clicked."
 4:   End Function
 5: </script>
 6:
 7: <script type="text/javascript">
 8:   $(function () {
 9:      $("#clickableThing1").click(handleClick);
10:   });
11: </script>

...generates the following error on line 9:

"Object doesn't support this property or method"

Replacing line 9 with the following, however, works as desired:

$("#clickableThing1").click(function() {
   handleClick();
});

I've tried passing handleClick to click() as both document.handleClick and as this.handleClick to no avail.

While I can certainly continue to wrap the VBScript calls in anonymous JavaScript functions, that seems unnecessarily verbose as, surely those functions must be defined in the DOM somewhere, right?

Can anyone tell me how I can refer to those VBScript functions directly?

1 Answer 1

1

I'm not sure that you can. I think if you try, the VBScript function is just going to get evaluated in place and its return value will be passed into click().

I'll offer another solution, though it may not meet your requirements. You can use the jQuery attr() function to assign an inline handler to the DOM element.

In my experience, when using VBScript functions as event handlers, you need to specify them using parens or include a language="vbscript" attribute on the DOM element.

<script type="text/javascript">
$(function() {

    // This should work (using parens)...
    $("#clickableThing1").attr("onclick", "handleClick()");

    // or, so should this (no parens on function call)...
    $("#clickableThing1").attr("language", "vbscript").attr("onclick", "handleClick");
});
</script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.