Goose Posted April 25, 2008 Share Posted April 25, 2008 Here is my situation: var myString = 'this is the right string'; obj.onmouseover = function(e) { showTip(e, 'this is the wrong string'); }; Since the onmouseover function can't see the myString variable, due to scope, I am unable to pass the contents of myString to the function. I thought I would try a global variable, but since the function that does this will get called multiple times it will only use the last value that the global variable was set to. Is there a way to pass multiple arguments into the onmouseover function? I know this is incorrect, but something like this: var myString = 'this is the right string'; obj.onmouseover = function(e, myString) { showTip(e, myString); }; Thanks much. Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted April 26, 2008 Share Posted April 26, 2008 is it ok to use use a javascript framework? I could fix it with no trouble at all using mootools or prototype Quote Link to comment Share on other sites More sharing options...
nogray Posted April 28, 2008 Share Posted April 28, 2008 I assume you are using this for a tooltip, since each object (html element) will have it's own tip, you can simple keep the string value inside the function () (like the wrong string) for each object. Second option is to use the title attribute in the HTML element and use the "this" scope in your function to get the title for example HTML... <input type="text" title="Hello World" id="input_1" /> Script... document.getElementById('input_1').onmouseover = function(e){ showTip(e, this.title); }; Not Tested Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.