asp.net - how to write data from a table row when a table row is clicked using jquery? -
to explain further... have asp.net table , textbox. there multiple rows in table. right now, have jquery code allows users click on rows , find link in row , take user url. here code:
<script type="text/javascript"> var selected = null; $(document).ready(function () { $("#<%=orders_data.clientid%>").find("tr").click(function () { $(selected).removeclass("selected"); $(this).addclass("selected"); selected = this; }); $("#<%=orders_data.clientid%>").find("tr").click(function () { var href = $(this).find("a"); href.attr("target", "_blank"); window.open(href.attr("href")) }); }); </script>
now, instead of finding tag , opening link, how can make jquery take data selected row in table "orders_data" , write data in textbox? let me know if need further clarify anything!
please try using this
$('#<%=orders_data.clientid%> td').click(function(){ var row_index = $(this).parent().index(); alert(row_index); var col_index = $(this).index(); alert(col_index); $tr=$(this).parent(); alert($tr); var data1=$tr.find("td").eq(1).html(); var data1=$tr.find("td").eq(1).html(); alert(data1); $('#<%=asp.net_textid%>"').val(data2); });
logic
- get current td using
$(this)
. - get current td's parent ie tr using
$(this).parent()
. - find td using index.
live demo @ here
Comments
Post a Comment