Results 1 to 3 of 3

Thread: JS problem

  1. #1
    Join Date
    Oct 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JS problem

    im a n00b and i made this little script:

    Code:
    var menu_value = new Array('login','panel','show','search','support','stats');
    var i;
    
    for (i = 0; i < menu_value.length; i++)
    {
    	document.getElementById(menu_value[i]).style.display = 'none';
    }
    	document.getElementById(menu_value[1]).style.display = 'block';
    but document.getElementById functions stop the execution of the code. Why? thk

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    If you do not have one and only one element on the page for each of the id values in your array, that would cause an error. Even if you do, but the code runs before the browser has parsed all of the elements, you will get an error. If you need more help:

    Please post a link to the page on your site that contains the problematic code so we can check it out.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Oct 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    oh yes i dont remember to add the last element of the array :/ thk :P

Bookmarks

Posting Permissions

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