I have a table having 15 rows of text boxes with class foo
.
If I write something suppose in the 5th text box I want the same text to be written in all subsequent boxes i.e the 6th, 7th, 8th ... 15th.
The following code has done the job but only when I change value by clicking on input field. But I want the code to work even if value of input field is changed indirectly say by another text box (suppose I have another single textbox and if I write any number there the content of 5th textbox is replaced by the sum of 5th textbox and single textbox).
How to modify the code? I have tried on('change'
in place of on('input'
, but get no result.
jQuery($ => {
$('.foo').on('input', e => {
$(e.target).closest('tr').nextAll('tr').find('.foo').val(e.target.value);
});
});