Home arrow HTML arrow Page 3 - React and ToChoose Functions for a Menu for All Browsers
HTML

React and ToChoose Functions for a Menu for All Browsers


Welcome to the sixth part of a nine-part series that shows you how to build a menu for all browsers. In this part we continue to take a look at the JavaScript functions, specifically the react() and toChoose() functions.

Author Info:
By: Chrysanthus Forcha
Rating: 3 stars3 stars3 stars3 stars3 stars / 2
June 10, 2009
TABLE OF CONTENTS:
  1. · React and ToChoose Functions for a Menu for All Browsers
  2. · The Parameters of the react() function
  3. · The toChoose() Function
  4. · The toChoose() Function Continued

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
React and ToChoose Functions for a Menu for All Browsers - The toChoose() Function
(Page 3 of 4 )

One of the objectives of the code is that, when you do not want to see any drop down or sub menu, you should click the BODY element outside the drop down or sub menu. When you do this, any drop down menu or sub menus on the screen should be removed.

However, when you click a menu item in the drop down or sub menu, you do not want the drop down menu or sub menu to be removed. Whenever you click the menu item, the BODY element indirectly receives a click. This indirect click is supposed to remove the drop down or sub menus.

To prevent this, we have to use the toChoose() function. The toChoose() function is called whenever you click a cell of the drop down menu or sub menu. When you click any of these cells, this function is called before the BODY element receives the indirect click. This function name is the value of the onclick attribute for any of these cells.

The function takes the ID of the cell as an argument. It sets the subMenuJustClicked global variable to true. The function called when the BODY element receives a click, either directly or indirectly, first checks to see if this variable is false. If it is false, it removes the drop down or sub menus; if it is true, it does not remove them. This is the toChoose() function:


var subMenuJustClicked = false; //for removing sub menus


function toChoose(ID)

{

currCellBgColor = document.getElementById(ID).style.backgroundColor; //background color of the current cell

 

if ((currCellBgColor == "firebrick")||(currCellBgColor == "#b22222")||(currCellBgColor == "rgb(178, 34, 34)"))

subMenuJustClicked = true;

}


The function uses the only global variable, subMenuJustClicked. This is the only global variable in the code. This function has just one main statement, which is an if-statement. The condition of this if-statement is the only code segment that really addresses the particular needs of different browsers. So this is the code segment I have been talking about that really addresses peculiarities of different browsers. Fortunately it is a very short code segment. You can think of it as a one-line code segment.

Before we look at the particular issues addressed, let us see what the function does. The if-state checks to see if the background color of the cell the mouse pointer is on, is firebrick. If it is firebrick, it sets the  subMenuJustClicked global variable to true. The statement before this if-statement in the function retrieves the background color of the cell.


blog comments powered by Disqus
HTML ARTICLES

- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5
- BBC Adopts HTML 5, Mozilla Addresses Issues
- Advanced Sticky Footers in HTML and CSS
- HTML and CSS Sticky Footers
- Strategy Analytics Predicts HTML5 Phones to ...
- HTML5 Guidelines for Web Developers
- Learning HTML5 Game Programming
- More Engaging CSS3 and HTML Background Effec...
- Engaging HTML and CSS3 Background Effects
- More Web Columns with CSS3 and HTML
- Columns with CSS3 and HTML
- Creating Inline-Block HTML Elements with CSS
- Drag and Drop in HTML5: Parsing Local Files

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials