PDA

View Full Version : Java script event and parameters



aitor
06-09-2005, 07:36 AM
Hi all!

I am new forum user. My work is mainly in GIS programming (maps, routes, etc), more precisely i am developing a web map app.

I am trying to keep separated js code form HTML and CSS, but i have some problems that i cannot resolve, for example, when i use:
<a id="myID">Hello</a>

then in a js file i put:

var a = document.getElementById("myID");
a.onmousedown = myFunction;

myFunction() {
alert(this.id);
}

But the problem is, what if I want to pass more parametes than event or this, i mean, what if the function is myFunction(param1,param2,param3). How can i handle this?

jscheuer1
06-09-2005, 07:59 AM
<body>
<a id="myID">Click</a>
<script type="text/javascript">
var a = document.getElementById("myID");
a.onmousedown = function(){myFunction('&nbsp;Hello&nbsp;','green','yellow')};

function myFunction(text, clr, bkgr) {
a.innerHTML=text;
a.style.color=clr;
a.style.background=bkgr
}

</script>
</body>

aitor
06-09-2005, 10:55 AM
Thats exactly what I want! Thank you! :D