Reputation: 76
I am writing a code for proboards.com. The code is going to be used to give categorys individual styles.
In the array:
catEdit[0]
is the category name and
catEdit[1]
is the id that the user wishes to give that cateory so that they can apply styles to it using CSS.
In the script below I have first looped through the array and then looped through the categorys on the users forum, stated an argument, and based on the argument gave the category an id.
Something is not right. Can someone please tell me what I am doing wrong?
Thank you in advance.
<script type= "text/javascript">
//Individual Category Styles
var catEdit=[
["General", "general"],
["Tester", "tester"],
["New Category", "newcat"]
];
var td= document.getElementsByTagName("td"),i;
for(i=0; i<catEdit.length;i++){
for(i=0; i<td.length;i++){
if(td[i].className== "catbg" && td[i].innerHTML.match(catEdit[i][0])) {
td[i].id=catEdit[i][1]
}
}
}
</script>
Upvotes: 0
Views: 112
Reputation: 23268
You should definitely not use i
as the loop variable for both loops. Consider using a different variable for the inner loop.
Upvotes: 6
Reputation: 298176
Both of your loops have the same index variable, i
, which will not work well at all. Consider using i
and j
as the index variables for the loops:
for (var i = 0; i < catEdit.length; i++) {
for (var j = 0; j < td.length; j++) {
...
Upvotes: 4