javascript - How to get count value increamented within loop -


table1.rows [0]. Tried to use the console using cells [1]. Inner HTML => "number" also tried this code table1.rows [0]. Sales [1] WinnerHTML! = Null => true

But if I try this code below:

HTML:

  & lt; Table id = "table1" & gt; & Lt; TR & gt; & Lt; TD & gt; Price & lt; / TD & gt; & Lt; TD & gt; & Lt; / TD & gt; & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; Price & lt; / TD & gt; & Lt; TD & gt; Price & lt; / TD & gt; & Lt; / TR & gt; & Lt; Table & gt;  

Javascript:

 for  (var i = 0; i & lt; table1.rows.length; i ++) {for (var j = 0; j and lieutenant; table 1. rosh [i]. Seals [j] .arfer html (j ++) {if (table 1. ro [ii] seals [ja] .non html! = Null) { Var count = 0; Calculation = count + 1; Warning (count); }}}  

  1. table 1 is not Define. You need to use document.getElementById to get a reference of your table element.
  2. On line 2, you j & lt; Table1.rows [i] .cells [j] .innerHTML . It does not make any sense and it does not make it j & lt; Table1.rows [i] .cells.length .
  3. You need to move your count variable outside of your loop, otherwise it will always be equal to 1.

Change your code to:

  var table1 = document.getElementById ('table1'); Var calculation = 0; (Var i = 0; i & lt; table1.rows.length; i ++) {for (var j = 0; j & lt; Table 1 .rows [i] .cells.length; j ++) {if (Table1.rows [i] cells [j] .winnerHTML! = Null) {count ++; Warning (count); }}  

.


Comments