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.
Choosing Sub Menus for a Common Browser Menu - The Statements in the for-loops (Page 3 of 4 )
At a particular iteration, the first statement in the inner for-loop gets the value of the Boolean variable (if it is there) of the corresponding cell in the Boolean Table, and assigns it to the boolVar variable. The second statement gets the SPAN number (if it is there) from the corresponding cell in the Number Table.
The next statement is an if-statement. It verifies if a SPAN element is displayed in the cell of the iteration. It does this by checking to see if boolVar is equal to “true.” If the condition is true, then the statements in the if-block are executed.
This block cleans the table cell at the iteration. The first statement in the block forms the ID of the Table Cell at the iteration.
The next statement forms the ID of the SPAN element that has to be replaced by the original copied version. The statement after that makes the copy.
The following two statements sets the content of the corresponding cells in the Boolean and Number Tables respectively to “”.
Now the subMenuJustClicked global variable should only be true if you have just clicked a sub menu item; otherwise, it should always be false. When the variable is true, the sub menus are not “removed.” Before the function ends, this variable is set to false.
In this way, when next the BODY element receives a click, the function will remove the sub menus, unless a sub menu item was clicked as well. The if-test “if (subMenuJustClicked == false)” checks this.