Hi,
I have a page with lots of hidden divs which are revealed based on choices made at each 'layer'.
So I've used naming convention which represents the order in which each div becomes visible - 'a100', 'a200', 'a300' for the first 'layer'; 'b100', 'b200', 'b300' for the second; 'c100, 'c200', 'c300' for the third ... etc
I'm writing the javascript functions to hide and show the appropriate divs and its getting out of hand pretty quickly - I have to 'showdiv' each div in the sequence that the user chooses, and also 'hidediv' every other choice which could potentially have been made (since if a user goes back a step in the sequence and clicks on a different choice it needs to hide what has already been displayed).
What I'm after is a way to use 'hidediv' to span multiple divs using the naming convention above - like using a partial name plus asterisk to find all the names which match the partial name given. But preferably it would recognise alphanumeric order...
Like if I could use:
[html]<A href="javascript:hidediv('b*')">click here</A>[/html]
to hide all divs with ids beginning with 'b' or later in the alphabet
Here's the javascript:
[html]
<script language="JavaScript">
function hidediv(id) {
//safe function to hide an element with a specified id
if (document.getElementById) { // DOM3 = IE5, NS6
document.getElementById(id).style.display = 'none';
}
else {
if (document.layers) { // Netscape 4
document.id.display = 'none';
}
else { // IE 4
document.all.id.style.display = 'none';
}
}
}
function showdiv(id) {
//safe function to show an element with a specified id
if (document.getElementById) { // DOM3 = IE5, NS6
document.getElementById(id).style.display = 'block';
}
else {
if (document.layers) { // Netscape 4
document.id.display = 'block';
}
else { // IE 4
document.all.id.style.display = 'block';
}
}
}
</script>
[/html]
and here's some html:
[html]
choose <A href="javascript:showdiv('a100');hidediv('a200');h idediv('b100');hidediv('b200');hidediv('c100');hid ediv('c200')">a100</A> or <A href="javascript:showdiv('a200');hidediv('a100');h idediv('b100');hidediv('b200');hidediv('c100');hid ediv('c200')">a200</A>
<DIV id=a100 style="DISPLAY: none">a100 content<BR><BR>choose <A href="javascript:showdiv('b100');hidediv('b200');h idediv('c100);hidediv(c200')">b100</A> or <A href="javascript:showdiv('b200');hidediv('b100');h idediv('c100');hidediv('c200')">b200</A></DIV>
<DIV id=a200 style="DISPLAY: none">a200 content<BR><BR>choose <A href="javascript:showdiv('b100');hidediv('b200');h idediv('c100);hidediv(c200')">b100</A> or <A href="javascript:showdiv('b200');hidediv('b100');h idediv('c100');hidediv('c200')">b200</A></DIV>
<DIV id=b100 style="DISPLAY: none">b100 content<BR><BR>choose <A href="javascript:showdiv('c100');hidediv('c200')"> c100</A> or <A href="javascript:showdiv('c200');hidediv('c100')"> c200</A></DIV>
<DIV id=b200 style="DISPLAY: none">b200 content<BR><BR>choose <A href="javascript:showdiv('c100');hidediv('c200');" >c100</A> or <A href="javascript:showdiv('c200');hidediv('c100');" >c200</A></DIV>
<DIV id=c100 style="DISPLAY: none">this is c100 content</DIV>
<DIV id=c200 style="DISPLAY: none">this is c200 content</DIV>
[/html]