Click to See Complete Forum and Search --> : logic


gverner
01-25-2004, 07:36 AM
The hardest part about this programming for me is the logic. I am making a menu that uses a + or - sign to show if the menu can expand or collapse.

Everything works until you try to open both at the same time then my + and - get out of sync. What is the best logic to use?

I made a variable named click to catch if the status of the button had been clicked before or not. Thanks for any help.
See below...

<script>

var click=true;

function exp(strTag,strDiv){




var elem = document.getElementById(strTag);

elem.style.display=='none'? elem.style.display='block':elem.style.display='none';

if(click == false){

click=true;

document.getElementById(strDiv).innerHTML ="<CENTER><font face=verdana color=ffffff>(+)</CENTER>";
}else{

click=false;
document.getElementById(strDiv).innerHTML ="<CENTER><font face=verdana color=ffffff>(-)</CENTER>";

}
}
</script>


In the page...

<tr bgcolor=#ffcc66 onclick="exp('table1','table1_div');">

<div ALIGN="left" id=table1_div style="diplay:inline;">
<CENTER>
<font face=verdana color=ffffff>(+)</font>
</CENTER>
</div>

crh3675
01-25-2004, 08:01 AM
<script>

var click=false;

function exp(strTag,strDiv){

var elem = document.getElementById(strTag);

if (elem.style.display=="none" || elem.style.display==""){
elem.style.display="block";
str="<CENTER><font face=verdana color=ffffff>(-)</CENTER>";
click=true;
}else{
elem.style.display="none";
str="<CENTER><font face=verdana color=ffffff>(+)</CENTER>";
click=false;
}
document.getElementById(strDiv).innerHTML=str;
}
</script>

Also, make sure to fix your DIV style, you have "display" misspelled (diplay):

<div ALIGN="left" id=table1_div style="display:inline;">

--Craig

gverner
01-25-2004, 09:35 AM
Thank you again so much. i have a hard time with the logic of things......being a graphic guy the left right brain thing i guess. thanks again!

second ?? this code is limited to browsers is there a code similar that would be good for all browsers?

crh3675
01-26-2004, 08:32 AM
All DOM compliant browsers should render this fine. Browsers like Netscape 4.x will not. I wouldn't worry about that too much though.

--Craig

gverner
01-26-2004, 08:35 AM
Thanks again !!