mjholden
asked on
JavaScript and browser differences for showing/hiding divs
I am having browser issues with a function that is supposed to show one div and hide another. After the page loads, they are supposed to switch so that the previously visible div is hidden and the previously hidden div is visible. This works great in IE, but in Netscape both divs are shown all the time. In Safari, only the content div shows. I would like for this to behave properly in all major browsers if at all possible.
Here's the function:
<script type="text/javascript">
<!--
function showMessage() {
if(document.all){
//browser="ie"
document.all.MessageDiv.st yle.visibi lity = "visible";
document.all.ContentDiv.st yle.visibi lity = "hidden";
}
else if(document.layers){
//browser="NN4";
document.MessageDiv.visibi lity = "show";
document.ContentDiv.visibi lity = "hide";
}
else if(!document.all && document.getElementById){
//browser="NN6";
document.getElementByID("M essageDiv" ).style.vi sibility = "visible";
document.getElementByID("C ontentDiv" ).style.vi sibility = "hidden";
}
}
-->
</script>
This function is just for showing the message/hiding the content. At the end of the page I then switch them. The rest of the page is asp/html. I don't know JavaScript well at all and don't usually use it, but I didn't know of another way to do this. Any assistance would be greatly appreciated.
Here's the function:
<script type="text/javascript">
<!--
function showMessage() {
if(document.all){
//browser="ie"
document.all.MessageDiv.st
document.all.ContentDiv.st
}
else if(document.layers){
//browser="NN4";
document.MessageDiv.visibi
document.ContentDiv.visibi
}
else if(!document.all && document.getElementById){
//browser="NN6";
document.getElementByID("M
document.getElementByID("C
}
}
-->
</script>
This function is just for showing the message/hiding the content. At the end of the page I then switch them. The rest of the page is asp/html. I don't know JavaScript well at all and don't usually use it, but I didn't know of another way to do this. Any assistance would be greatly appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you both for your comments. I'll try out some of the suggestions from the post mentioned.
Is there any (relatively easy) way to do what I want without JavaScript?
Is there any (relatively easy) way to do what I want without JavaScript?
ASKER
Thank you astaec! The post you suggested contained code that was very close to what I needed, so I was able to fix the problem.
YAY! I'm so pleased. Thank you for the good news and the fine grade. I'm happy I could help you.
Best wishes,
":0) Asta
Best wishes,
":0) Asta
Good Luck
Rockman