Home arrow HTML arrow Page 3 - More on the React Function for a Common Browser Menu
HTML

More on the React Function for a Common Browser Menu


Welcome to the sixth part of a ten-part series on building a common browser menu. We continue in this part with the in-depth analysis of the react() function. As you may recall, in the last part we noted that the function was composed of five code segments, and began analyzing them. In this part, we shall complete the details of the react() function's fourth code segment and talk about the fifth code segment.

Author Info:
By: Chrysanthus Forcha
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
April 10, 2009
TABLE OF CONTENTS:
  1. · More on the React Function for a Common Browser Menu
  2. · The Fifth Code Segment Details
  3. · Code for the Fifth Code Segment
  4. · More on the Fifth Code Segment

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
More on the React Function for a Common Browser Menu - Code for the Fifth Code Segment
(Page 3 of 4 )

This is the code for the fifth segment:


//if rooArr is empty and if subColNo is not empty

if ((subColNo != "")&&(rootArr == ""))

{

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

{

//form the TD ID

tdIDSub = 'TD' + i + subColNo;

//form ID of SPAN

spanID = 'S' + tdID.charAt(2) + tdID.charAt(3) + i + subColNo;

if (document.getElementById(spanID)) //if it exist

{

//first clear what was in the cell, if anything

oldSpanID = 'S' + document.getElementById('TNo').rows[i].cells[subColNo].innerHTML;

if (document.getElementById(oldSpanID))

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


document.getElementById(tdIDSub).style.backgroundColor = "brown";

document.getElementById(spanID).style.display = "block";

//indicate the cell that is displayed in the boolean table

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

//indicate the first two numbers of the shown SPAN ID in the table that shows the Nos.

number = "" + tdID.charAt(2) + tdID.charAt(3) + i + subColNo;

document.getElementById('TNo').rows[i].cells[subColNo].innerHTML = number;

}

}

}


All of the statements are in an if-block. The condition in the if-statement tests if the second argument, subColNo of the react() function, is not empty and if the last argument, rooArr of the react() function, is empty. If these two tests are true, it means a sub menu is required directly from a cell in a drop down menu.

The code then proceeds with the statements in the if-block. There is one main statement in the if-block, which is the for-loop. The for-loop iterates through five indices. We have five iterations here, because there are five cells in a column (for our example). In your own project, this number may change.

The first statement in the for-loop creates the ID of the cell for the iteration (index). It uses the iteration number as the row number for the ID and it uses the second parameter, subColNo of the react() function, as the column number for the ID.

The second statement in the for-loop develops the ID of the SPAN element. The number of digits in the number part of the SPAN element for the sub menu we are trying to develop is four. The first two digits of this SPAN element are the digits of the number part of the present cell. The ID of any cell begins with the letters "TD" and is followed by two numbers. The ID of any SPAN element for a sub menu developed from a drop down menu begins with "S" followed by four digits. The second statement forms the SPAN ID by first attributing the letter, "S," followed by the first digit from the cell ID, followed by the second digit from the cell ID, followed by the iteration number, followed by the column number of the cell in the sub menu.


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