javascript - Hide table row based on a value within text input -


i found javascript example on site hides rows based on reading value directly within cell within row, need read value within text input field.

here's javascript i'm using:

function hide() { var tbl = document.getelementbyid('table'),     rows = tbl.tbodies[0].children, l = rows.length, i,     filter = function(cells) {          var values = [             parseint(cells[0].firstchild.nodevalue.replace(/,/g,''),10),             parsefloat(cells[1].firstchild.nodevalue.replace(/,/g,''))         ];         if( values[1] < 1) return false;         return true;     }; for( i=0; i<l; i++) {     if( !filter(rows[i].cells)) rows[i].style.display = "none"; } } 

here's html:

 <tr> <tdrow 1</td> <td>1<input id="quantity1" name="quantity1" class="numericvalue" type="text" value="1" /></td> </tr> <tr> <td>row 2</td> <td>2<input id="quantity2" name="quantity2" class="numericvalue" type="text" value="2" /></td> </tr> <tr> <td>row 3</td> <td>3<input id="quantity3" name="quantity3" class="numericvalue" type="text" value="0" /></td> </tr> <tr> <td>row 4</td> <td>4<input id="quantity4" name="quantity4" class="numericvalue" type="text" value="0" /></td> </tr> <tr> <td>row 5</td> <td>0<input id="quantity5" name="quantity5" class="numericvalue" type="text" value="0" /></td> </tr>  <input id="btnsubmit" onclick="hide();" type="submit" value="hide" /></p> 

as is, js read "0" in row 5 , hide it, want rows 3,4, , 5 input values of "0" hidden. how @ input value? table in input values start @ "0" (for quantity), 1 or more of values changed.

thanks.

just need change single line:

parsefloat(cells[1].firstchild.nodevalue.replace(/,/g,'')) 

becomes

parsefloat(cells[1].firstelementchild.value.replace(/,/g,'')) 

fiddle


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -