Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

i m trying to get the value of array from post

Tags:

jquery

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>
like image 203
Rozer Avatar asked Nov 12 '22 03:11

Rozer


1 Answers

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(...);
});
like image 82
Alnitak Avatar answered Nov 15 '22 01:11

Alnitak