I have a table with
<TABLE id="dataTable">
<TR>
<TD><INPUT type="checkbox" class="chk"/></TD>
<TD><INPUT type="text" value="data1"/></TD>
<TD><INPUT type="text" value="data2"/></TD>
<TR>
<TD><INPUT type="checkbox" class="chk"/></TD> <TD>Data 2</TD>
<TD><INPUT type="text"/></TD>
<TD><INPUT type="text"/></TD>
</TABLE>
Say I have many rows in the table. I want to fetch the data present in each cell and use it as per my requirements.
I tried doing
$(function()
{
$("#somebutton").click(function()
{
$("#dataTable").find('tr').each(function(){
if($(this).find('input.chk').is(':checked'))
{
var val1 = $(this).find('td:eq(1)').html();
var val2 = $(this).find('td:eq(2)').html();
alert(val1);
alert(val2);
}
});
});
});
But the output I get from this is as follows
<input type="text" value="data1">
<input type="text" value="data2">
I just want the output to be given as the value present inside the Text of the cell.
I tried using .val() and .value() , but it gives me error. Please guide me how to achieve this.
Thanks,
var data1 = $(this).find('td:eq(0):input[type="text"]').html();. Let me know if it solved your issue.