You are using extremely overly complex code or at least it appears so. With all of these definitions identical to their counterparts, all references to them are apparently meaningless:
Code:
highlightcolour="black";
highlightbackground="#CC9999";
highlighttext="<input type='checkbox'>";
normalcolour="black";
normalbackground="#CC9999";
normaltext="<input type='checkbox'>";
Simply accessing the elements' involved display property is all that is required. There are several scripts available here on DD for doing this. For simply collapsing and revealing elements with similar, numbered id's - this would suffice:
Code:
<script type="text/javascript">
function displayOne(idNum){
var idPrefix='cdiv'
var elNumber=4
for (var i=0;i<elNumber;i++)
document.getElementById? document.getElementById(idPrefix+i).style.display='none' : document.all[idPrefix+i].style.display='none';
document.getElementById? document.getElementById(idPrefix+idNum).style.display='' : document.all[idPrefix+idNum].style.display='';
}
</script>
Two variables to set (red) above:
1 ) idPrefix - the prefix id name, in this example 'cdiv' so elements like:
HTML Code:
<div id="cdiv0"></div>
can use id's 'cdiv0', 'cdiv1', etc.
2 ) elNumber - the number of elements to act upon, if you have four of these ('cdiv0' through 'cdiv3') set it to 4 if you only have two ('cdiv0' and 'cdiv1') set it to 2.
Note: Do not set the initial display property for these elements in the stylesheet. Use either inline style or javascript (preferred). Example using javascript:
Code:
onload=function (){
var idPrefix='cdiv'
var elNumber=4
for (var i=0;i<elNumber;i++)
document.getElementById? document.getElementById(idPrefix+i).style.display='none' : document.all[idPrefix+i].style.display='none';
}
A nice touch would be to use document.write to create a style rule like so:
Code:
if(document.getElementById)
document.write('<style type="text/css" id="showhide">\
.showhide{\
display:none;\
}\
</style>')
that creates a class to be applied to all of the 'cdiv#' id'ed elements so that they are all collapsed to begin with but, only in javascript enabled browsers. Then disable it once things get rolling:
Code:
document.getElementById('showhide').disabled=1
Bookmarks