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.
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.