Thursday, July 26, 2012

how to use the variable in a for loop in Javascript?



I have a dataTable which I need to iterate through. so I have this code:



var tableSize = $(\'#j_idt11\\\\:dataTable tbody tr\').length;
for(i = 0;i< tableSize;i++){
var test1 = document.getElementById(\"j_idt11:dataTable:0:updFoodType\").textContent;
if(test1 == \"food\")
alert(\"hey\");
}


but I really want to use the i in the for loop. I thought something like this:



var tableSize = $(\'#j_idt11\\\\:dataTable tbody tr\').length;
for(i = 0;i< tableSize;i++){
var test1 = document.getElementById(\"j_idt11:dataTable:[i]:updFoodType\").textContent;
if(test1 == \"food\")
alert(\"hey\");
}


but that doesn\’t work. how must I use the syntax? Thanks!






Rating: 3 out of 5 based on 3 ratings



The post how to use the variable in a for loop in Javascript? appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/how-to-use-the-variable-in-a-for-loop-in-javascript.html

No comments:

Post a Comment