I am having trouble with a for loop and printing out an array. Here is the function:
1 function showmenu(SectionName) {
2 TabName = SectionName + "Tab";
3 TabContainer = document.getElementById('ProductTabs');
4 TabArray = TabContainer.getElementsByTagName('a');
5 NumInArray = TabArray.length;
6 for (i=0; i < NumInArray; i++) {
7 document.write(TabArray.id);
8 document.write(" i=" + i);
9 }
10 document.write("<br>done");
11 }
When I run this on the page, it pulls 3 elements in to the Array (which is correct). I declare NumInArray because if I just use TabArray.length in the for loop, it will only cycle once regardless of whether line 7 is in or not. The output that I get from this function is
PhotosTab i=0
However, if I leave line 7 out, I get
i=0 i=1 i=2
done
Any idea why line 7 kills the script?
1 function showmenu(SectionName) {
2 TabName = SectionName + "Tab";
3 TabContainer = document.getElementById('ProductTabs');
4 TabArray = TabContainer.getElementsByTagName('a');
5 NumInArray = TabArray.length;
6 for (i=0; i < NumInArray; i++) {
7 document.write(TabArray.id);
8 document.write(" i=" + i);
9 }
10 document.write("<br>done");
11 }
When I run this on the page, it pulls 3 elements in to the Array (which is correct). I declare NumInArray because if I just use TabArray.length in the for loop, it will only cycle once regardless of whether line 7 is in or not. The output that I get from this function is
PhotosTab i=0
However, if I leave line 7 out, I get
i=0 i=1 i=2
done
Any idea why line 7 kills the script?