Rozer
Rozer

Reputation: 65

i m trying to get the value of array from post

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>

Upvotes: 5

Views: 94

Answers (3)

Alnitak
Alnitak

Reputation: 339955

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(...);
});

Upvotes: 1

jiguang
jiguang

Reputation: 362

just use .parent(), then you can get tr, also can get tr's id.

$("input").blur(function(){
  alert($(this).parent().attr('id'));  
});

Upvotes: 0

Adil Shaikh
Adil Shaikh

Reputation: 44740

find the row -id of textbox when blur is triggred

$("input").blur(function() {
  var rowID = $(this).closest('tr').prop('id');
  // some more stuff
})

Upvotes: 0

Related Questions