Changed the name attribute to id but not sure how to amend my JavaScript.
Hi there,
I've just changed the "name" attribute being used in a piece of working JavaScript to "id".
The script allows me to hide/show sections of text on a page...
var sections = new Array('beginners', 'higher')
function closeAll()
{
var i;
for (i=0; i<sections.length; i++) {
var obj = document.getElementById(sections[i]);
if (eval("typeof document.img"+sections[i])!='undefined') {
eval("document.img"+sections[i]+".src='images/'+'plus.png'");
obj.style.display = 'none';
}
}
}
function switchBlock(SWEET) {
var obj = document.getElementById(SWEET);
if (eval("typeof document.img"+SWEET)!='undefined') {
if(obj.style.display == 'none') {
eval("document.img"+SWEET+".src='images/'+'minus.png'");
obj.style.display = 'block';
}
else {
eval("document.img"+SWEET+".src='images/'+'plus.png'");
obj.style.display = 'none';
}
eval("document.img"+SWEET+".blur()");
}
}
function toFront(section)
{
document.all['beginners'].style.visibility='hidden';
document.all['higher'].style.visibility='hidden';
eval('document.all[\''+section+'\'].style.visibility="visible"')
}
On the actual html page, there's a piece of coding that goes like this...
<a href="JavaScript:switchBlock('higher')"><img src="images/plus.png" name="imghigher" width="18" height="18" /></a>
When I change it to...
<a href="JavaScript:switchBlock('higher')"><img src="images/plus.png" id="imghigher" width="18" height="18" /></a>
...the JavaScript does not work.
Can someone please tell me what I need to change in the JavaScript code.
Thank you.