Tuesday, 15 July 2014

calculate textboxes for each table row in jquery -



calculate textboxes for each table row in jquery -

i looping through set of dynamic table rows, trying capture value of cell2 in each table row using jquery, returns value of cell2 row1 every time, though recognises cells1 right row value each time, can tell me going wrong please? see below sample code.

thanks help received.

//html <table class=planttable> <tr> <td><input type=text value=0 class=cell1></td> <td><input type=text value=0 class=cell2></td> <td><input type=text value=0 class=cell3></td> </tr> <tr> <td><input type=text value=0 class=cell1></td> <td><input type=text value=0 class=cell2></td> <td><input type=text value=0 class=cell3></td> </tr> <tr> <td><input type=text value=0 class=cell1></td> <td><input type=text value=0 class=cell2></td> <td><input type=text value=0 class=cell3></td> </tr> </table> //jquery tr = $(".planttable tr").length; $(tr).each(function () { $(this).find($(".cell1").blur(function () { cell1val = parseint($(this).val()); cell2val = parseint($(".cell2").val()); //returns value of cell2 in first row only? }));

inside find you're finding again, @ document top, finding row1 cell2. if want sibling of current item seem to, this:

$("tr").each(function () { $(this).find($(".cell1")).blur(function () { cell1val = parseint($(this).val()); cell2val = parseint($this.siblings(".cell2").val()); }); });

this retrieve value of cell2 next cell1 found.

jquery

No comments:

Post a Comment