HTML
  Home arrow HTML arrow Background Images for a Menu for All Brows...
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  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
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? 
HTML

Background Images for a Menu for All Browsers
By: Chrysanthus Forcha
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2009-06-17

    Table of Contents:
  • Background Images for a Menu for All Browsers
  • Using Background Images
  • Changes to the Code
  • Review of the Project

  • 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


    Background Images for a Menu for All Browsers


    (Page 1 of 4 )

    In this seventh part of a nine-part series on building a menu that works in all browsers, we complete the discussion of the JavaScript functions. We go on to see how we can use background images for menu items instead of background colors. We shall start winding up the series at the end of this part.

    The removeSubMenu() Function

    The BODY element receives a click when you click it outside a sub menu item (that is, outside the drop down or sub menu). When the BODY element receives a click, this function is called. The start tag of the BODY element has the following attribute:

    onclick="removeSubMenu()"


    Now, this is the removeSubMenu() function:


    function removeSubMenu()

    {

    if (subMenuJustClicked == false)

    {//remove sub menus

    //first remove drop down tables

    for (x=0;x<5;x++)

    {

    DDID = "DDT" + x;

    document.getElementById(DDID).style.display = "none";

    }

    //call the functions to remove the sub tables

    remove2NumID();

    //remove the main table for the sub menus

    document.getElementById('MT').style.display = "none";

    }

    //reset the subMenuJustClicked variable

    subMenuJustClicked = false;

    }



    The first statement is an if-statement. It verifies that the global variable, subMenuJustClicked is false; that is, it verifies that a sub menu item was not clicked. If it was not clicked, it means it has to remove any drop down and/or sub menu that was displayed. The block of the if-statement does this.

    The first statement in this block is a for-loop. This loop sets the value of the display property of every drop down menu to "none." In this way, any drop down menu that was displayed is removed. The next statement in the block calls the remove2NumID() function. We know that this function also calls the remove3NumID() function. In this way, all the sub menus in our example are removed. The next and last statement in the block removes the main table that holds the drop down and sub menus.

    After the if-statement, whose block we have discussed, we have one statement, which is the last in the function. The statement sets the subMenuJustClicked global variable to false, independent of whether a drop down or sub menu was removed. False is its initial and default value. The value of this variable changes depending on whether a sub menu item was clicked or not.

    Whenever the toChoose(ID) function is called, the removeSubMenu() function is called immediately after. This sequence is in accordance with the clicking events triggered: the onclick event of a sub menu item, followed by the indirect onclick event of the BODY. So the subMenuJustClicked variable is true only for a short time. If it remains true after the removeSubMenu() function has been executed, the next time you click the BODY element outside the menu, the drop down or sub menus will not be removed. In other words, the if-block will not be executed.

    At this point, we have discussed all the JavaScript functions of this series. What we have to do now is  see how to use images as background for the menu item cells.

    More HTML Articles
    More By Chrysanthus Forcha


     

    HTML ARTICLES

    - Comparing Browser Response to Active Client ...
    - Testing Browser Response to Active Client Pa...
    - Active Client Pages: Completing the Code for...
    - ACP and Browsers: Setting up an Example
    - How Browsers Respond to Active Client Pages
    - Completing a Tree with Active Client Pages
    - HTML Form Verification and ACP
    - Building an ACP Tree
    - Completing an ACP 3D HTML Table Image Gallery
    - Building an ACP 3D HTML Table Image Gallery
    - A Multiple Page Image Gallery with Active Cl...
    - Building an Image Gallery with Active Client...
    - Concluding a Menu for All Browsers
    - A Vertical Menu for All Browsers
    - Downloading Long HTML Pages with ACP







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek