SysAdmin1030
asked on
How to show/hide multiple independent DIVS with javascript (Two Seperate Elements)?
I'm in a bit of a predicament.
I need a quick and easy to implement solution preferably based in javascript.
I'm attempting to create a splash page that needs to use a show/hide feature for two different sections for the page.
Here is the idea.
First, you select a region which makes a list of locations show up for that region. This process is complete using the following javascript:
The second part is where the script above can no longer support my needs.
After selecting the region you can select one of the locations which would then show/hide a variety of information about that location.
Essentially, I have one show/hide script that works for selecting a region which shows the locations in that region. Now, I need to add an additional component that allows me to select the location and show information about that location without screwing everything else up. All on one page. No database. Yikes!
Any help would be greatly appreciate!
I need a quick and easy to implement solution preferably based in javascript.
I'm attempting to create a splash page that needs to use a show/hide feature for two different sections for the page.
Here is the idea.
First, you select a region which makes a list of locations show up for that region. This process is complete using the following javascript:
<script language="JavaScript">
//here you place the ids of every element you want.
var ids=new Array('a1','a2','a3','a4','a5','a6','a7','a8','b9','b10');
function switchid(id){
hideallids();
showdiv(id);
}
function hideallids(){
//loop through the array and hide each element by id
for (var i=0;i<ids.length;i++){
hidediv(ids[i]);
}
}
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>
The second part is where the script above can no longer support my needs.
After selecting the region you can select one of the locations which would then show/hide a variety of information about that location.
Essentially, I have one show/hide script that works for selecting a region which shows the locations in that region. Now, I need to add an additional component that allows me to select the location and show information about that location without screwing everything else up. All on one page. No database. Yikes!
Any help would be greatly appreciate!
ASKER
Hi Proculopsis,
This is basically what the javascript I have does except switches out element by element rather than by all of them.
What I would need next is for each of those elements 'a1'....'a10' to be able to open up new information by a click.
For example if you clicked 'a1' it would list 'a5', 'a6' (which my javascript above does) then you if select 'a5' I need it to display 'a8' below.
Does this make sense?
I appreciate your help!
This is basically what the javascript I have does except switches out element by element rather than by all of them.
What I would need next is for each of those elements 'a1'....'a10' to be able to open up new information by a click.
For example if you clicked 'a1' it would list 'a5', 'a6' (which my javascript above does) then you if select 'a5' I need it to display 'a8' below.
Does this make sense?
I appreciate your help!
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
The answers where all correct but they did not give me the result necessary; mainly because I could not explain the question well enough.
Does something like this help:
Open in new window