I'm new to jQuery and I'm trying to find the row ID of the textbox when blur is triggered, but I couldn't make it work so far.
All I need is something like #employee_0
in form_data
when the blur event is triggered on my first textbox.
$("input").blur(function () {
$('input').each(function (index, value) {
var form_data = $("#employee_" + index).find('input').serialize();
$.ajax({
url: "<?php echo site_url("HomeController / calculate_time_lap "); ?>",
type: 'POST',
data: form_data,
success: function (result) {
$('input').closest('tr').find('.TextBox3').val(result);
}
});
return false;
});
and here is my view page:
<tr id="employee_0"><input type ="textbox"></tr>
<tr id="employee_1"><input type ="textbox"></tr>
<tr id="employee_2"><input type ="textbox"></tr>
<tr id="employee_3"><input type ="textbox"></tr>
<tr id="employee_4"><input type ="textbox"></tr>
Within the event handler the row ID will be available as:
$(this).closest('tr').attr('id');
Note that your HTML isn't legal - you need <td>
elements inside the <tr>
.
If, instead, you're just trying to find (and serialise) all of the inputs that are in the same row, you don't actually need the ID at all, you can just traverse the DOM from where you are:
$("input").blur(function () {
var form_data = $(this).closest('tr').find('input').serialize();
$.ajax(...);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With