I have a table which have multiple rows with input fields having same names
<tr>
<td>
<input type=text name=icode[] id=icode>
</td>
<td>
<input type=text name=description[] id=description>
</td>
<td>
<input type=text name=rprice[] id=rprice>
</td>
<td>
<input type=text name=discount[] id=discount>
</td>
<td>
<input type=text name=fprice[] id=fprice>
</td>
</tr>
Now using on focusout function I want to populate the value of description and rprice from the database. But I am unable to do it for the same row. While browsing around I found this piece of code
$(_this).parents('tr').find('#description').val(obj.description);
but it updates for all the rows and the specific row.
So basically when i type 1 in icode on row 2, I want description and rprice of row 2 to be updated only not all rows.
I have posted a sample code for reference: http://jsfiddle.net/nA7RL/
Thanks in advance.
Use parent instead of parents:
from jquery: http://api.jquery.com/parents/
The .parents() and .parent() methods are similar, except that the latter only travels a single level up the DOM tree.
In your case, the parents method is going to the higher level tr, and from there, the find method is locating all the existing description fields.