Home arrow HTML arrow Page 2 - Choosing Sub Menus for a Common Browser Menu
HTML

Choosing Sub Menus for a Common Browser Menu


In this part of the series, we discuss how the sub menus, including drop-down menus, are removed from the screen. We shall also see how the series will progress. This is the ninth part of a ten-part series covering the creation of a common browser menu.

Author Info:
By: Chrysanthus Forcha
Rating:  stars stars stars stars stars / 0
May 01, 2009
TABLE OF CONTENTS:
  1. · Choosing Sub Menus for a Common Browser Menu
  2. · The removeSubMenu() Function
  3. · The Statements in the for-loops
  4. · Some Comments

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Choosing Sub Menus for a Common Browser Menu - The removeSubMenu() Function
(Page 2 of 4 )

The onclick event of the BODY element calls this function. The aim of this function is to remove all the sub menus from the screen. When the BODY element is clicked, this function is called. Any other element is in front of the BODY element. When you click any other element, the BODY element indirectly receives a click. So when you click any other element, this function is still called. Everything being equal, when you click either the BODY element or some other element, the sub menus will be removed.

When you click a sub menu item, we do not want this function do anything. As we said above, when you click a sub menu, the subMenuJustClicked global variable is set to true. Under this condition the function will not remove the sub menus on the screen. This is the function:


function removeSubMenu()

{

if (subMenuJustClicked == false)

{//remove sub menus

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

{

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

{

boolVar = document.getElementById('TB').rows[i].cells[j].innerHTML;

spanNum = document.getElementById('TNo').rows[i].cells[j].innerHTML;

if (boolVar == "true")

{

tdID = 'TD' + i + j;

spanID = 'S' + spanNum;

document.getElementById(tdID).innerHTML = document.getElementById(tdIDBack).innerHTML;

document.getElementById(tdID).style.background = "transparent";

document.getElementById('TB').rows[i].cells[j].innerHTML = "";

document.getElementById('TNo').rows[i].cells[j].innerHTML = "";

}

}

}

}

//reset the subMenuJustClicked variable

subMenuJustClicked = false;

}


You have an if-statement. It is the block of the if-statement that removes the sub menus. The condition of the if-statement tests to see if the subMenuJustClicked global variable is false. If it is false, it means the sub menus can be removed; that is, the if-block can be executed. If it is true, it means no sub menu should be removed. If it is true, it means a sub menu item was clicked. If it is false, it means a sub menu item was not clicked.

The if-block has a for-loop as its first statement. The for-loop has an immediate inner for-loop. These two for-loops iterate through the whole table, row by row, cell after cell. Removing a sub menu means removing the individual sub menu items. For each cell having a SPAN element displayed, the content of the corresponding cell in the Boolean Table has the word “true.”

A sub menu item consists of the table cell whose background color is brown, a SPAN element whose value for the display property is “block” and a link inside the SPAN element. So you “remove” a menu item by copying the original content of the cell from the corresponding cell in the Copy Table into the cell. The value of the display property of any SPAN element in the Copy Table is "none," meaning that it cannot be seen and it does not occupy space. “Removing” a sub menu item also means making the background of the cell transparent.


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 10 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials