MyBB Community Forums

Full Version: Javascript onclick show div
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey,

I'm trying to add a 'dropdown' menu to my first theme. However I'm struggling to find a javascript code that will work.

My friend gave me this but I can't get it working:
<a href="#" onclick="document.getElementById('myDiv').style.display='visible'>Click to show the div</a> 

<script type='text/javascript'> 
function atload() {
}
window.onload=atload;
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById('myDiv').style.visibility = 'hidden'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.myDiv.visibility = 'hidden'; 
} 
else { // IE 4 
document.all.myDiv.style.visibility = 'hidden'; 
} 
} 
</script>

Does anyone see what needs to be done to fix it?

It will need to be backwards compatible so if javascript isn't enabled the div will automatically display.

Cheers,
Clarkie
I'll give it a go thanks but it looks a little bit different to what I'm after.
No I'm afraid a popup menu doesn't work for this.