SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard
    Join Date
    Oct 2004
    Location
    Newport Beach
    Posts
    1,760
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multiple Variables in Single Javascript Function?

    I have this function:

    function DoViewMENU(tid1) {
    document.getElementById(tid1).style.display = "";
    if(tid1 == 'entertainment') {
    DoHideIFRAME('world');
    }
    if(tid1 == 'world') {
    DoHideIFRAME('entertainment');
    }

    }
    I plan on having a bunch of sections and was wondering if there was a way to give more than one variable like so:

    if(tid1 == 'world') {
    DoHideIFRAME('entertainment, politics');
    }

    If somebody clicks on the 'entertainment' button I need to make sure all other button/menus are closed... and there are going to be a bunch.

    Thanks
    Ryan
    Upcoming Movies - Movie News. Updated Daily.
    Movie Trailers - Awesome trailer site. Nuff said.

  2. #2
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Location
    London, UK
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Certainly possible. You can call DoHideIFRAME like this:

    PHP Code:
     DoHideIFRAMES('entertainment','politics','younameit');
    function 
    DoHideIFRAMES() {
      for (var 
    i=0i<arguments.length;i++)
        
    DoHideIFRAME(arguments[i]);

    Here's another alternative which is less pure:

    PHP Code:
     DoHideIFRAMES('entertainment,politics,younameit');
    function 
    DoHideIFRAMES(names) {
      var 
    namesarray names.split(',');
      for (var 
    i=0i<namesarray.length;i++)
        
    DoHideIFRAME(namesarray[i].replace(/^\s+|\s+$/g,''));


  3. #3
    SitePoint Wizard
    Join Date
    Oct 2004
    Location
    Newport Beach
    Posts
    1,760
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow, Thanks!

    Ryan
    Upcoming Movies - Movie News. Updated Daily.
    Movie Trailers - Awesome trailer site. Nuff said.


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
  •