VBscript to write javascipt function that pass arguments

This example is much simplified as the original script.
VBScript is making a value, passes this to Javascript, which puts that value into a div tag.
Now, as you see in the VBScript, the value contains a call to a javascript function. It shows perfectly in HTML, but the call can’t be made when clicking the link.

Is it possible in VBscript to write dynamic hardcoded javascipt function that pass arguments?

<script type="text/vbscript">
Dim m
m = "my message"
message = "<a href='#' onclick='javascript:test(" & m & ");'>click</a>" 

sendtojs(message)
</script>
<script type="text/javascript">
function sendtojs(message){
var messContainer = document.getElementById("messages");
messContainer.innerHTML = message;
}

function test(m){
alert(m);
}
</script>

HTML:
<div id="messages"></div>

All scripts are in the same html page.
I went on VB forums, but they’re not quite helpful :s

Weird… This should be in the Javascript part of the forum I think but someone moved it over here :fangel:

You’re talking about using vbscript in the browser as opposed to vbscript on the server right?

Well, it’s about VBscript, not running on a web hosting server, but in a folder on a hard drive for a small intraweb.

Well it’s a project with Excel data that need to be read by Internet Explorer.
VBScript seemed the easiest way…

(If I would do this project on my own, I did it with web technologies like I do for my personal web projects (php/MySQL, datasases).
Why with Excel? Ask that question to my boss… (he’ll explain about budgets and infrastructure we don’t get for the project).)

Anyway… the purpose of the script would be:
One of those data will be used as arguments in javascript functions, as you see in the code. That javascript function will do other things with this value later on. I tried to make this example as simple as possible without the rest of the complex code I already have.

Can anyone help?

Hey bulevardi,
I thought that might be the case.

So all of the processing will be done in IE and not on the server right?

If it’s going to run on IE only why don’t you do everything in VBScript? It’s been a while since I’ve coded any VBScript for client side but as I recall it has a lot to offer for IE only intranet sites.

Ok I see, I’ll give it a try in VBscript only.

The thing is I’m better in Javascript and new in VBScript.
So I thought I just get the values I need with VBScript and work further with Javascript as I’m already used to :slight_smile:

Yup, I think you’ll have more success in doing it all vbscript or all javascript because in order to hand off a variable in javascript to vbscript or vice-versa, you’ll have to create some sort of wrapper or intermediate variable that both languages can access. It’s probably more work and less efficient than just using one language or the other.

Good luck with the project!

Andrew

It’s working already.

For those who are interested, I wrote a Javascript VBScript tutorial:
http://bulevardi.be/?content=scripting&example=exvb1#7

Contains the following stuff:

  • [Basics in combining Javascript with VBScript]
  • [Calling a VBScript function from Javascript]
  • [Calling a Javascript function from VBScript]
  • [Passing a value from Javascript to VBScript]
  • [Calling a VBScript function with multiple parameters from Javascript]
  • [Passing a value from VBScript to Javascript]
  • [Calling a Javascript function with multiple parameters from VBSscript]
  • [Calling VBScript functions from another frame]
  • [Let VBScript relocate]