paulrouke
12-16-2004, 09:25 AM
Hi,
I'm having trouble working out why my javascript code is showing more div layers that what I would like on each click of a href="javascript:changeDiv(1,1,7); button/link.
Apologies for the size of the post but I presumed the more I supply the easy it will be to understand where I'm coming from......
My setup up is this:
3 column layout
column 1 = a uk map graphic, with 7 clickable image maps relating to 7 areas of the uk (ie midlands, north west, north east etc)
column 2 = when a user clicks an area, this column is populated with a clickable list of customers from that particular area
column 3 = when a use clicks a customer, this column is populated with a testamonial from that particular customer
My code uses the following javascipt functions:
//the function to begin the change of the div been shown
function changeDiv(pass, level, count) {
var tonum = level+count;
for (j=level;j<tonum;j++)
{
if (j == pass)
{
showDiv(j);
}
else
{
hideDiv (j);
}
}
}
//the function to show that particular div
function showDiv(pass) {
var divs = document.getElementsByTagName('div');
for(i=0;i<divs.length;i++){
if(divs[i].id.match(pass)){
if (document.getElementById)
divs[i].style.visibility="visible";
else
if (document.layers) // Netscape 4
document.layers[divs[i]].display = 'visible';
else // IE 4
document.all.hideshow.divs[i].visibility = 'visible';
}
}
}
//the function to hide the other divs which aren't selected
function hideDiv(pass) {
var divs = document.getElementsByTagName('div');
for(i=0;i<divs.length;i++){
if(divs[i].id.match(pass)){//if they are 'see' divs
if (document.getElementById) // DOM3 = IE5, NS6
divs[i].style.visibility="hidden";// show/hide
else
if (document.layers) // Netscape 4
document.layers[divs[i]].display = 'hidden';
else // IE 4
document.all.hideshow.divs[i].visibility = 'hidden';
}
}
}
The 7 region divs in column 2 use ids 1-7 id="1", id="2" etc
The testamonial divs in column 3 use ids starting from 8, going up ie. id="8", id="9", id="10" etc
The functions and parameters I call to display the 7 regions are:
href="javascript:changeDiv(1,1,7);"
href="javascript:changeDiv(2,1,7);"
href="javascript:changeDiv(3,1,7);"
href="javascript:changeDiv(4,1,7);"
href="javascript:changeDiv(5,1,7);"
href="javascript:changeDiv(6,1,7);"
href="javascript:changeDiv(7,1,7);"
My issue I haven't been able to solve is this:
when the 1st region script is called (href="javascript:changeDiv(1,1,7);") my div in column 3 with id="10" displays.
I presume this has something to do with the fact that this id includes the number 1, even though I haven't actually called the function href="javascript:changeDiv(10,1,7);"
Please can someone enlighten me!?
Once I have this working correctly I expect to have around 70 individual divs, each numbered accordingly ie. 21, 43, 55 etc etc, so in the current set-up any number of divs will be displayed at each function call.
Thanks in advance for any assistance.
I'm having trouble working out why my javascript code is showing more div layers that what I would like on each click of a href="javascript:changeDiv(1,1,7); button/link.
Apologies for the size of the post but I presumed the more I supply the easy it will be to understand where I'm coming from......
My setup up is this:
3 column layout
column 1 = a uk map graphic, with 7 clickable image maps relating to 7 areas of the uk (ie midlands, north west, north east etc)
column 2 = when a user clicks an area, this column is populated with a clickable list of customers from that particular area
column 3 = when a use clicks a customer, this column is populated with a testamonial from that particular customer
My code uses the following javascipt functions:
//the function to begin the change of the div been shown
function changeDiv(pass, level, count) {
var tonum = level+count;
for (j=level;j<tonum;j++)
{
if (j == pass)
{
showDiv(j);
}
else
{
hideDiv (j);
}
}
}
//the function to show that particular div
function showDiv(pass) {
var divs = document.getElementsByTagName('div');
for(i=0;i<divs.length;i++){
if(divs[i].id.match(pass)){
if (document.getElementById)
divs[i].style.visibility="visible";
else
if (document.layers) // Netscape 4
document.layers[divs[i]].display = 'visible';
else // IE 4
document.all.hideshow.divs[i].visibility = 'visible';
}
}
}
//the function to hide the other divs which aren't selected
function hideDiv(pass) {
var divs = document.getElementsByTagName('div');
for(i=0;i<divs.length;i++){
if(divs[i].id.match(pass)){//if they are 'see' divs
if (document.getElementById) // DOM3 = IE5, NS6
divs[i].style.visibility="hidden";// show/hide
else
if (document.layers) // Netscape 4
document.layers[divs[i]].display = 'hidden';
else // IE 4
document.all.hideshow.divs[i].visibility = 'hidden';
}
}
}
The 7 region divs in column 2 use ids 1-7 id="1", id="2" etc
The testamonial divs in column 3 use ids starting from 8, going up ie. id="8", id="9", id="10" etc
The functions and parameters I call to display the 7 regions are:
href="javascript:changeDiv(1,1,7);"
href="javascript:changeDiv(2,1,7);"
href="javascript:changeDiv(3,1,7);"
href="javascript:changeDiv(4,1,7);"
href="javascript:changeDiv(5,1,7);"
href="javascript:changeDiv(6,1,7);"
href="javascript:changeDiv(7,1,7);"
My issue I haven't been able to solve is this:
when the 1st region script is called (href="javascript:changeDiv(1,1,7);") my div in column 3 with id="10" displays.
I presume this has something to do with the fact that this id includes the number 1, even though I haven't actually called the function href="javascript:changeDiv(10,1,7);"
Please can someone enlighten me!?
Once I have this working correctly I expect to have around 70 individual divs, each numbered accordingly ie. 21, 43, 55 etc etc, so in the current set-up any number of divs will be displayed at each function call.
Thanks in advance for any assistance.