When I edit a row of the table, I have the index of that row. Now I want to get the value of a field from the next row. I wrote the following code but it always returns undefined.please guide me.Note: The index of the rows may not be consecutive
Table:
<table id="Itemdatatable" class="table table-striped table-hover"> <thead> <tr> <th>Row</th><th>Col1</th> <th>Col2</th> <th> operation </th> </tr> </thead> <tbody> <tr> <input id="Items_Index" name="Items.Index" type="hidden" value="0"><input name="Items[0].Item_InvoiceID" type="hidden" value="41446"> <input name="Items[0].Item_StoreID" type="hidden" value="6"> . . . <input name="Items[0].Item_Percentage" type="hidden" value="0"> <td> 1 </td> <td> aaaa </td><td> bbbb </td><td> <a onclick="EditItemRow(0)">Edit</a> </td> </tr><tr> <input id="Items_Index" name="Items.Index" type="hidden" value="1"> <input name="Items[1].Item_InvoiceID" type="hidden" value="55546"> <input name="Items[1].Item_StoreID" type="hidden" value="13"> . . . <input name="Items[1].Item_Percentage" type="hidden" value="10"> <td>2</td><td>cccc</td><td>ddd</td> <td><a onclick="EditItemRow(1)">Edit</a></td> </tr> . . . </tbody> </table>
function EditItemRow(rowIndex) { var currentRow = $('table#Itemdatatable').find('tr').eq(rowIndex); var nextRowIndex = $(currentRow).next().find('input[name="Items.Index"]').val(); . . . }