Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery get next input element value in <td>

I have some piece of an html table which reads like

<table>
    <tr>
        <td>
            <input type="text" class="myclass" name="first_ele[]" value="100" />
        </td>
        <td>
            <input type="text" class="anotherclass" name="secon_ele[]" value="" />
        </td>
    </tr>
</table>

I have a piece of jquery that will get the value of the element that contains class "myclass" on keyup and I am getting the proper value. I need to get the value of the next input element. FYI , The table gets rows added dynamically. My issue is I don't know how to point to the next available input element.

my jquery to get the element which has the class "myclass" is as follows.

$('.tInputd').keyup(function(){
    var disc = $(this).val();
});

your help is greatly appreciated.

like image 375
Ela Buwa Avatar asked Dec 04 '22 09:12

Ela Buwa


1 Answers

Try

$('.myclass').on('keyup', function () {
    var disc = $(this).closest('td').next().find('input').val();
});

or

$('.myclass').on('keyup', function () {
    var disc = $('.anotherclass').val();
});
like image 117
Anton Avatar answered Dec 20 '22 23:12

Anton