Hello friends, I have a series input
that fills up little by little, but I have two in particular that I would like to calculate, so my question is how can I use onchange or something similar in js so that when the state of both changes, it executes me another method
<input type="text" id="capacidadPago" name="name" value="" />
<input type="text" id="capacidadRenta" name="name" value="" />
<input type="text" id="respuesta" name="name" value="" />
so that when paymentcapacity and rentcapacity change their value return the sum of both in the response input
I think this could help
Lines 1 through 6 are the listener for the onchange event.
Lines 2 and 3 are for retrieving the value of thePaymentCapacity and RentCapacity inputs according to their id.
Line 5 is to assign the sum of the values retrieved on lines 2 and 3, after conversion to int (paraeInt), to the input whose id is response.
Lastly, lines 8 and 9 are for assigning the listener to thePaymentCapacity and RentCapacity inputs.
Example
Explanation :
id
to each of theinputs
; both those that will receive the numbers typed by the user, and the one in which the result will be writtenlistener
in the eventchange
to detect when its status changed and then assignvalue
the value of said valueinput
to the box in its property.resultado
arrow function
wenumero1
detect the eventchange
but now ofnumero2
values
of each text and assign it to the input that has the idresultado
parseInt()
to each of theinputs
to prevent them from being concatenated and instead add