0
  onclick='showthread(); myjsfunction()' language='vbscript'>

somewhat to the effect of the above but does not work. Where showthread is a vbscript function and myjsfunction is a javascript function.

Thank you.

6
  • Client-side VBScript? In 2012? Why? Commented Nov 21, 2012 at 4:25
  • This will not work. You've just mixed server and client-side code. Resolve the issue differently. Tell us what you really want to do Commented Nov 21, 2012 at 4:44
  • Try updating your onclick to call a single JS function, and from that function call your VB function. That's how I remembered it working the last time I did this, which was a long time ago, but also I just tried it and it worked (in IE8). @polin - OP has already said what is required. This is all client-side. Commented Nov 21, 2012 at 4:50
  • @polin: VBScript can be used client-side in IE-based engines. Commented Nov 21, 2012 at 5:00
  • @T.J.Crowder well I didn't know that. Eager to know. Can you give any example or reference link. This would be very helpful Commented Nov 21, 2012 at 5:04

2 Answers 2

1

It seems to me your best bet is to abandon onxyz handlers and hook things up properly via the DOM — or a combination of the two.

For instance, your element could hook up the VBScript via onxyz (I've copied your syntax for that):

<div id="mydiv" onclick="showthread();" language="vbscript">

...and a <script> tag in the document could hook up the JavaScript:

<script>
document.getElementById("mydiv").attachEvent("onclick", myjsfunction);
</script>

(I'm using attachEvent there because I know you're using an IE-based engine, if you're using VBScript.)

Or of course, have two <script> elements (one JavaScript and one VBScript) and hook up both functions via the DOM:

<div id="mydiv">

<script>
document.getElementById("mydiv").attachEvent("onclick", myjsfunction);
</script>

<script type="application/x-vbscript">
document.getElementById("mydiv").attachEvent "onclick", showthread
</script>

(Or whatever the correct MIME type is for VBScript. Or you can probably use language="VBScript" with an IE-based engine.)

Sign up to request clarification or add additional context in comments.

2 Comments

how do I attach the event to table row? Because that's where the onclick event is sitting <tr onclick="showthread()...
@like-a-trainee: Using any of the various DOM methods to identify the table row -- getElementById, getElementsByTagName, the rows property... Or, of course, since the click event bubbles, just hook it on the table or tbody element and refer to event.target.
0

I'm not very familiar with VBScript but it seems to me that you could do something like

function myjsfunction() {
    window.location = "vbscript:showthread();"

    // other JS code
}

to call the VBScript function from JS. This is certainly hacky but I don't know of any better way.

If it's possible, though, it's probably best to convert to JavaScript entirely.

1 Comment

do we have to do window.location? Can't we keep it in the same window?

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.