I'm having problems calculating and displaying a number in an input field via jquery. considering I have two input fields, the first one accepts a number and the second one displays this number + 100. works as it should do, as long as you enter the number in the first field via the keyboard. changing the number with the little arrow buttons on the right side of the input field however, doesn't always refresh the second input field at once, especially if you try to "hammer" those little arrow buttons: if you keep clicking them, the number isn't refreshed, until you move the mouse (tested with win 10 and google chrome).
I have found several topics regarding this problem and tried different approaches (see commented code lines), none of them work for that case.
$(document).ready(function() {
$('#inp_1').on('keyup', function() {
calc();
});
$('#inp_1').on('change', function() {
calc();
});
function calc() {
var old_val = parseInt($('#inp_1').val());
var new_val = old_val + 100;
$('#inp_2').val(new_val);
/*
$("#inp_2").attr('value', new_val);
$("#inp_2").trigger("change");
*/
//$("#inp_2").attr('defaultValue', newVal);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="number" step="1" id="inp_1" value="">
<input type="number" step="1" id="inp_2" value="">