Hi,
I have a very simple javascript function which works onclick.
There is an unordered UL list on my page which the function loops through and sets all of the id’s for each LI to null.
It then takes the name of the specific LI that has been click (which is passed in the function variables) and changes it’s ID to “current”
It’s basically so I can show which of the current sections on the page is the current one being used.
Here’s my code:
on a li link:
onclick=”navcontrolchange(this,’innercontrol_projects’);”
the function:
function navcontrolchange(element,innercontrolname,mainnavname){
alert (element)
//grab the info from the top navigation bar nodes
liArray=document.getElementById(“nav”).childNodes;
i=0;
//loop through and set all the id’s to nothing (thus clearing their style settings
while(liArray[i]){
liArray[i].id=””;
i++;
}
//finally change the one we’ve actually clicked on to “current” so this is picked up by the css
element.id=”current”;
//grab the LIinfo from the inner controls list
var menuliArray = document.getElementById(“innercontrols”).getElementsByTagName(“li”);
//loop settings all diplsya to nothing
for (var j=0; j<menuliArray.length; j++) {
menuliArray[j].style.display = “none”;
}
//finally set the one we’ve selected from the top navigation to be visible
document.getElementById(innercontrolname).style.display=”block”;
var innermenuliArray = document.getElementById(innercontrolname).getElementsByTagName(“li”);
for (var k=0; k<innermenuliArray.length; k++) {
innermenuliArray[k].style.display = “block”;
}
}
see? all very simple.
Now I have an additional request… when the user moves a page I need to keep this state so I use an onload behaviour to fire that same function. .however, the onclick behavious used the “this” keyword so it knows which LI was clicked.
When I move pages I am able to pass querystring info so I can keep a track of things. however I cannot see how to pass the “this” value
If I do an alert(this) on the fucntion I just get [object] so that’s no help
Basically I need to alter:
navcontrolchange(this,’innercontrol_<%=MainSection%>’);
to remove the “this” keyword and replace with a hardcoded word/number for the li which has been clicked.
Any ideas?