Ad

How To Set Focus On Input Control Of Last Row Second Column Of Html Table

- 1 answer

I have to set focus on the last row second column while clicking add new row button.

enter image description here

row append code:

$("#tblDetItems").append('<tr><td align="right">' + sl_no + '</td><td td style="width: 200px; height: 13px;"><input type="text"  id="txtCode" value="" style="width: 190px; height: 13px;" /></td><td>' + "" + '</td><td>' + "" + '</td><td align="right" style="width: 100px; height: 13px;"><input type="text"  id="txtStdRate" value="0.00" style="width: 100px; height: 13px;" /></td><td align="right" style="width: 100px; height: 13px;"><input type="text"  id="txtLbrCharge" value="0.00" style="width: 100px; height: 13px;" /></td><td align="right" style="width: 100px; height: 13px;"><input type="text"  id="txtRcvryCost" value"0.00" style="width: 100px; height: 13px;" /></td><td style="width:80px; height: 18px;"><select id="cmbUseId_tbl"  style="width: 80px; height: 18px;"><option value="Y" selected="selected">Yes</option><option value="N">No</option></select></td></tr>');
Ad

Answer

you can give any selector to every textbox you create i.e. class name.

<input type="text" class="fooClass" value="" />

then use jQuery last keyword to make it focus after generating last row.

$( ".fooClass:last" ).focus();
Ad
source: stackoverflow.com
Ad