Somnath Paul
Somnath Paul

Reputation: 190

Identifying the id which has changed in the class

i have a html table, where all elements (textbox) of one column (of table) belong to same class and each textbox has different unique id, and the table has multiple column and rows. If a textbox value is changed, it should return the other column value (position value) of the same row in whose textbox value is changed.

<tr style="background-color: rgb(200, 200, 200);" id="node-13600" class="child-of-node-0 row byte_lenght_1 initialized">
    <td style="padding-left: 34px;">terminat</td>
    <td style="padding-left: 15px">format</td>
    <td style="padding-left: 15px">
        <input class="main_text" id="main_type_13600">
    </td>
    <td class="length" style="padding-left: 15px">1</td>
    <td class="position" style="padding-left: 15px">0</td>
    <td style="padding-left: 15px">HTermin
        <input type="hidden" name="row" value="13600">
    </td>
</tr>
<tr style="background-color: rgb(200, 200, 200);" id="node-13601" class="child-of-node-0 row byte_lenght_1 initialized">
    <td style="padding-left: 34px;">termin</td>
    <td style="padding-left: 15px">wc_type</td>
    <td style="padding-left: 15px">
        <input class="main_text" id="main_type_13601">
    </td>
    <td class="length" style="padding-left: 15px">1</td>
    <td class="position" style="padding-left: 15px">1</td>
    <td style="padding-left: 15px">##: eph ##: tdm_c ##: all_c ##: choose_c ##: root_c
        <input type="hidden"
        name="row" value="13601">
    </td>
</tr>

I am using the jquery for this :

$('.main_text').change(function() {
  var a= $(this).find('.position').val();
  alert (a);
});

however I am not getting any result, as expected !!!

Upvotes: 0

Views: 59

Answers (1)

Terence Jefferies
Terence Jefferies

Reputation: 358

I'm pretty sure this is what you are looking for:

$('.main_text').change(function() { 
    alert($(this).parent().parent().find('.position').html()); 
});

".find" looks for elements INSIDE of the element you are specifying. So it was looking for ".position" inside of ".main_text"

In addition, I have change ".val()" to ".html()" as val is used for retrieving the value of a input field, and you are attempting to retrieve the html contents of a table cell.

Hope this has helped.

Cheers,

TJ

Upvotes: 3

Related Questions