[Javascript] Passing a variable to a Function

liorean liorean at f2o.org
Thu Nov 20 13:40:14 CST 2003


Kevin.Gutch at mapinfo.com wrote:
> I would like to pass a value to a function [- - -]
> I really want to pass a dynamic value/variable to the function. How would I
> go about doing this in the function call? When I try it just gets passed as
> a String.
> 
> <a href="javascript:myFunction(myVariable);">myVariable</a>
> 
> Am I making myself clear?

I believe that code is executed within the document scope instead of the 
window scope. Try href="javascript:myFunction(window.myVariable);". 
However, I would recommend you to use the onclick event instead, be sure 
to return false after you call the function, and use # as the target for 
the href attribute.

-- 
liorean <mailto:liorean at user.bip.net>

ViewStyles, ViewScripts, ToggleStyles and GraphicsInfo bookmarklets and 
Theme Switcher, Cookies Handler scripts:
<http://liorean.web-graphics.com/>




More information about the Javascript mailing list