3
I need to show two pieces of information when the user enters the commission amount, in case the information that should show IR
and Valor líquido
.
For example, if the user types 1.200,00
, on the label IR
would appear 18,00%
(1,200 x 1.5%) and on the label Valor líquido
the net total (1,200 - 18) that it would give 1.182,00
.
I believe I would have to assemble some function in javascript, but I am layman with this language, or if there is any other way, all help will be welcome.
Obs. the intention is only shows the two values IR and Net Value without needing to save anything, because what I need to save even would be the value of the commission.
My code:
<form method="post"action="processa.php">
<label>Valor comissão:</label>
<input type="text" name="valor_comissao">
<label>IR:</label>
<input type="text">
<label>Valor Líquido:</label>
<input type="text">
<button type="submit">Enviar</button>
</form>
Excuse the ignorance, but need to import some library to use this function? could not perform the function here.. kk
– Smoke Rohden
@Smokerohden doesn’t need any library, it’s all native Javascript. If you can’t get it to work create a jsFiddle with an example I help. But as a test you can put Javascript after HTML in the page.
– Sergio
You could even create the variables of
inputs
with Destructuring– Isac
Got it. I put it in the end it worked!
– Smoke Rohden
Thanks @Sergio really worth it
– Smoke Rohden
@Isac yes, it would be cleaner
const [valor, ir, liquido] = [...document.querySelectorAll('form input')];
– Sergio