I want to increase the value entered in the amount input by 10% in real time and show it in the amount + commission input, how can I do it? I will be glad if you help me thank you
Using jQuery, read the input value on change and then calculate the final amount after commission and display it in the second input field which will be disabled.
$('input').on( "input", function() {
console.log( $( this ).val() );
let val = parseInt($(this).val());
let comm = 10;
let total = val + val*comm/100;
$('input[name="total"]').val(total);
});
2
Answers
You need to provide the code you have so we can help you.
However, you can make this with Jquery using
.change()
methodChange the yourinputID with the first input ID and yourSecondinputID with the result input ID.
EXTRA:
.keyup()
function is much better for this.change()
detects when the input changes, but.keyup()
detects when the user releases a key on the input and is much more efficient.Using jQuery, read the input value on change and then calculate the final amount after commission and display it in the second input field which will be disabled.