...

View Full Version : show/hide script with error information



coder_seth
03-06-2004, 08:21 AM
i am trying to create a simple switch to turn the main navigation of a site "on" and "off". here is my script:



function nav_display() { // show/hide nav
if (document.getElementById('sidebar').style.display == 'none') {
document.getElementById('sidebar').style.display = 'block';
document.getElementById('content').style.margin-left = '1.5em';
document.getElementById('nav_display_a').style.color = '#666';
} else {
document.getElementById('sidebar').style.display = 'none';
document.getElementById('content').style.margin-left = '170px';
document.getElementById('nav_display_a').style.color = '#FFF';
}
}

<div id="nav_display_btn">
<a id="nav_display_a" href="javascript:;" onclick="nav_display()" title="Click to show/hide the main menu.">&laquo;</a>
</div>


i am getting these errors:

-from firefox-
"Error: nav_display() is not defined"

-from IE-
"Error: Object expected"

this is essentially a carbon copy of another function i was using in another spot on the site. which works fine. or should at least. it's not working for me now either. do i maybe have something wrong on my machine? this seems like elementary JS and DOM manipulation. i am confoozled.. in all fairness, it is 2:20 AM.. :rolleyes:

coder_seth
03-06-2004, 08:29 AM
ah.. made the assumption that the margin property names were the same in JS when it in fact should be:


document.getElementByID('content').style.marginLeft

it works now. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum