Home arrow HTML arrow Page 4 - Making a Common Browser Menu React
HTML

Making a Common Browser Menu React


Welcome to the fifth part of a ten-part series that shows you how to make a drop-down browser menu that works on multiple browsers. In this part of the series, we begin an in-depth analysis of the react() function, which is the function that responds to the onmouseover event for each table cell.

Author Info:
By: Chrysanthus Forcha
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
April 03, 2009
TABLE OF CONTENTS:
  1. · Making a Common Browser Menu React
  2. · Third Code Segment of the react() Function
  3. · Details of the react() Function
  4. · The Fourth Code Segment: Details

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Making a Common Browser Menu React - The Fourth Code Segment: Details
(Page 4 of 4 )

This segment clears all the cells in the column that are not supposed to have a SPAN element shown. Let us go through the segment:


//Clear all the cells in the column that are not supposed to have a SPAN element shown

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

{

if (document.getElementById('TB').rows[i].cells[colNo].innerHTML != "true")

{

//form the IDs of sub menu column and backup cells

IDCol = "TD" + i + colNo;

tdIDBack = 'TDB' + i + colNo;

//reset the cell content

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

//also reset the background

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

//reset the Boolean and SPAN number tables as well

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

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

}

}


Here we have a for-loop. The for-loop has one statement, which is an if-statement. This if-statement has other statements inside its block. The for-loop goes through the column that has the cell, which called the react() function.

For each iteration, the segment first of all checks to see if a SPAN element is displayed in a cell where it is not supposed to be displayed. How does this come about? Well, following our setup, consider the case where you have a sub menu coming out from a drop down menu. Not all the cells in the sub menu have a brown background color; that is, not all the cells display a SPAN element. If you move your mouse pointer onto one of the cells in the sub menu, the second segment of the react() function will give the color brown to all the cells in the column with the sub menu. This is not what you want; you wanted the cells that do not have the SPAN element shown to be transparent. So this segment comes in and gives back to those cells their transparent color.

In order to see if a cell in the column (sub column) is not displaying a SPAN element, the segment uses the Boolean Table. Recall that for each cell in our table that has a SPAN element displayed, the Boolean Table has the content “true” in its corresponding cell. The condition of the if-statement tests to see if this content is not “true.” If the content is not “true,” it means the background color is supposed to be transparent and there is not supposed to a SPAN element there; in that case, the statements in the if-block are executed.

Before we look at the lines in the if-block, let us talk about the statement in the if-test. The cells of the Boolean and Number Tables do not have IDs. So to address the cells, you have to use the DOM’s row and column indices (with the object reference, row and column containers). The expression on the left hand side of the assignment operator of the statement is derived from DOM principles. We have seen this kind of expression elsewhere.

It's time to take a break. I'll see you in the next part of the series.


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

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