jmansa
07-16-2009, 12:32 PM
I'm trying to make one div default open, and that is working ok, but when I hit the link for the the other div to open, the first div is not closing... It closes when I hit the link for the first div...
var currentShowingDiv = document.getElementById('idShowHide1');
function doHideShow3(divName){
var objDiv = document.getElementById(divName);
if (currentShowingDiv && currentShowingDiv != objDiv) {
currentShowingDiv.style.display = 'none';
}
if(objDiv.style.display == ''){
objDiv.style.display = 'none';
} else {
objDiv.style.display = '';
currentShowingDiv = objDiv;
}
}
Here is the php:
include_once "js/showhide_report.php";
echo '<a href="javascript:void(null);" onclick="doHideShow3(\'idShowHide1\');">Div 1</a> | ';
echo '<a href="javascript:void(null);" onclick="doHideShow3(\'idShowHide2\');">Div 2</a><br><br>';
echo '<div id="idShowHide1" style="padding:0px 0px 25px 0px;width:100%x;">';
echo 'Show something here for DIV 1';
echo '</div>';
echo '<div id="idShowHide2" style="padding:0px 0px 25px 0px;width:100%x;display:none;">';
echo 'Show something here for DIV 2';
echo '</div>';
So just to clarify what I want is to have one div open as default (idShowHide1) and when the user hits the link for the second div (idShowHide2) the first div close and the other open... As it is now the first div does not close...
Hoping for help ;-)
var currentShowingDiv = document.getElementById('idShowHide1');
function doHideShow3(divName){
var objDiv = document.getElementById(divName);
if (currentShowingDiv && currentShowingDiv != objDiv) {
currentShowingDiv.style.display = 'none';
}
if(objDiv.style.display == ''){
objDiv.style.display = 'none';
} else {
objDiv.style.display = '';
currentShowingDiv = objDiv;
}
}
Here is the php:
include_once "js/showhide_report.php";
echo '<a href="javascript:void(null);" onclick="doHideShow3(\'idShowHide1\');">Div 1</a> | ';
echo '<a href="javascript:void(null);" onclick="doHideShow3(\'idShowHide2\');">Div 2</a><br><br>';
echo '<div id="idShowHide1" style="padding:0px 0px 25px 0px;width:100%x;">';
echo 'Show something here for DIV 1';
echo '</div>';
echo '<div id="idShowHide2" style="padding:0px 0px 25px 0px;width:100%x;display:none;">';
echo 'Show something here for DIV 2';
echo '</div>';
So just to clarify what I want is to have one div open as default (idShowHide1) and when the user hits the link for the second div (idShowHide2) the first div close and the other open... As it is now the first div does not close...
Hoping for help ;-)