JavaScript
  Home arrow JavaScript arrow Page 4 - Switching on Layers with Scripts
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Switching on Layers with Scripts
By: Dan Wellman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 6
    2004-06-08

    Table of Contents:
  • Switching on Layers with Scripts
  • Starting with a Basic HTML Page
  • VBScript Subroutines
  • Using an Array
  • JavaScript Version

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Switching on Layers with Scripts - Using an Array


    (Page 4 of 5 )

    Admittedly, the code is rather hefty for simple client-side layer switching. You could reduce the amount of code by using an array to store the z-indices of the tabs and a loop to rearrange their order upon each click, but I have found that this detracts from the look of the tabs. If you wanted to do this, you first declare the array, which would need to be global in order to be used in all of the separate subroutines:

    dim glblTabArray(3)

    The array has 4 values stored, but the fist value in an array is always 0, hence the 3 in brackets.  Now remove all of the tab1.style.zindex="3" lines of code from all of the onclick subroutines, leaving just the visibility lines. In each of the onclick subroutines, add a subroutine call, using the tab name as an argument (remember to change the tab name in each of the calls though):

    call tabchanger(tab1)

    Now to create the tabchanger subroutine:

    sub tabchanger(Clicked)
     dim Row
     for Row = 0 to 3
      If glblTabArray(Row).style.zindex > Clicked.style.zindex Then
                glblTabArray(Row).style.zindex = glblTabArray(Row).style.zindex - 1
      End if
     next
     Clicked.style.zindex = 3
    end sub

    This first sets the Row variable which will be synchronized with the z-indices, then uses a for...next loop to cycle through each of the z-indices, and changes them based on the results of the if statement.  Personally, I prefer the original code. Create a file first with the original code, then with the array code, you'll notice when testing them that the tab order looks better in the original code. This is why I prefer it.

    More JavaScript Articles
    More By Dan Wellman


     

    JAVASCRIPT ARTICLES

    - Using Mod_Security to Protect Your Server
    - Detecting and Countering Server Intrusions
    - Securing Your Web Server
    - Building a Secure Web Server
    - Protecting the Server
    - Book Review: Learning the Yahoo! User Interf...
    - Dynamically Generate a Selection List in a R...
    - Intergrate DWR into Your Java Web Application
    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget
    - Ajax Hack for Entering Information Without R...
    - EXT JS 2.1 Overview
    - Using the Style Object for Zebra Tables with...
    - Binary Searching
    - An Improved Approach to Building Zebra Tables






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT