I can’t figure out why this isn’t working. It changes to the first link and wont keep going. I’d also need it to loop through so when you click it always circles through the links I have a php variable that is the last #panelNum.
<html>
<head>
<script language="JavaScript"><!--
function findLinkByHref(href) {
for (var i=0; i<document.links.length; i++) {
if (document.links[i].href == href) return i;
}
return -1;
}
function changeLinkHref(id,newHref,oldHref) {
if (document.links.length > 0) {
if (document.getElementById) {
document.getElementById(id).href = newHref;
}
else if (document.all) {
document.all[id].href = newHref;
}
else {
var index = findLinkByHref(oldHref);
if (index > -1)
document.links[index].href = newHref;
}
}
}
//--></script>
</head>
<body>
<a id="myLink" href="#panel3" value="Change href" onClick="changeLinkHref('myLink','#panel4','#panel5','#panel5','#panel6')">somewhere</a>
</body>
</html>
if you return in an if, it still returns – thus stopping execution of your function.
This is the only for loop, thus the only place you are iterating through all of your links. It sounds like you want to do this in the changeLinkHref function, something like..