Hello. I’m trying to pass a var to a function using onclick, but when I run it, it plays the function onload, and does not work when I click the link. I’m used to AS3 where you can’t do this, so is javascript the same? If that’s the case, how can I get the object to the onclick function for later use?
This is my handler
[CODE]navLink.onclick = navClick(oSection);
And the function
[CODE]function navClick(S) {
alert(S);
return false;
}
and in context
[CODE]window.onload = initSite;
function initSite() {
var clientsDoc = Sarissa.getDomDocument(“”,””);
clientsDoc.async = false;
clientsDoc.load(“xml/client_data.xml”);
var navItemList = clientsDoc.getElementsByTagName(“navItem”);
//make main nav
for(i=0; i<navItemList.length; i++) {
var navLink = document.getElementById(“nav_”+(i+1));
//build XML object
var oSection = new Object();
oSection.linkName = navItemList[i].getAttribute(“name”);
var linkText = document.createTextNode(oSection.linkName);
navLink.appendChild(linkText);
navLink.onmouseover = navOver;
navLink.onmouseout = navOut;
navLink.onclick = navClick(oSection);
}
var links = document.getElementById(“nav_”+(i+1));
}
function navOver() {
this.parentNode.className = “active-link”;
}
function navOut() {
this.parentNode.className = “inactive-link”;
}
function navClick(S) {
alert(“”);
return false;
}
Thanks for any help you can offer.