Reputation: 447
I have created a table that has a text input box. I want to get the value of the text box value within the tr element.how do I do it?
$(document).on('click', '.overtime_send', function(){
$('#employee_table tr').each(function(row, tr){
var asd = $(tr).find('td:eq(3)').text();//get the value
var asd01 = $(tr).find('td:eq(4)').text();//not get the value of the text box
alert(asd);
});
});
above code with getting all the static content of table row.how do I get the text value into the variable within table data?
Upvotes: 1
Views: 4433
Reputation: 10237
Use the .find('input')
since you have just one input in your tr
and .val()
to get the value.
let your_array = [];
$(document).on('click', '.overtime_send', function() {
$('#employee_table tbody tr').each(function(row, tr) {
your_array.push({
emp_id: $(tr).find('td:eq(0)').text(),
input_val: $(tr).find('input').val()
});
});
});
Upvotes: 1
Reputation: 1895
You can try this.
$(document).on('click', '.overtime_send', function(){
$('#employee_table tbody tr').each(function(row, tr){
console.log("Get Html "+$(this).find("td:eq(4)").html());
console.log("Get Text box value"+$(this).closest().find("input[type='text']").val());
});
});
Upvotes: 0
Reputation: 22510
For 4 td contain input not a text element .so need to find input
value instead of text
$(document).on('click', '.overtime_send', function(){
$('#employee_table tr').each(function(row, tr){
var asd = $(tr).find('td:eq(3)').text();//get the value
var asd01 = $(tr).find('td:eq(4)').find('input').val();// value of input box
alert(asd);
});
});
Upvotes: 2