简体   繁体   中英

Change input value inside TD using row and column index

I'm new to jquery so please bear with me.

I have a table that has columns quantity, price, and amount. The amount column should be updated whenever there are changes in either quantity or price.

So far, here's my jquery event:

$('input.qtyPrice').on('change',function() {

   var rowIndex =  $(this).parent().parent().index();

    console.log($('#tableItems tr').eq(rowIndex).find('td').eq(4));

})

This writes the console [prevObject: o.fn.init[0], context: document, jquery: "2.1.0", constructor: function, selector: ""…]context: documentlength: 0prevObject: o.fn.init[0]__proto__: o[0]

I took that answer from another question here in Stackoverflow. My problem is, I can't seem to access the INPUT element (amount) inside the TD. 在此处输入图片说明 Sorry for my English. I appreciate your inputs. Thank you.

You don't have to access the rowIndex, you can directly find the amount like

$('input.qtyPrice').on('change', function () {

    var $tr = $(this).closest('tr');

    $tr.find('td:nth-child(5) input').val('updated')
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM