Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Banned
    Join Date
    Jan 2004
    Location
    Minneapolis, MN
    Posts
    387
    Thanks
    0
    Thanked 0 Times in 0 Posts

    show/hide script with error information

    i am trying to create a simple switch to turn the main navigation of a site "on" and "off". here is my script:

    Code:
    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..

  • #2
    Banned
    Join Date
    Jan 2004
    Location
    Minneapolis, MN
    Posts
    387
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ah.. made the assumption that the margin property names were the same in JS when it in fact should be:

    Code:
    document.getElementByID('content').style.marginLeft
    it works now.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •