Calculate percentage in real time

-2

I wanted to put 2 inputs in my page, 1 the user will put a number (any one) and in the front box will appear the division of that number in 50% in real time, how would I do that?

    
asked by anonymous 02.12.2018 / 20:02

1 answer

0

So to be able to do this, you would have to rely on JavaScript as well, since HTML is just a markup language and you can not make 'logical' codes in your language.

Given this, basically what you would have to do was pick up the number entered in the field and divide this number by a supposed "2" (being it the half of 1 number):

function dividirNumero() 
{
    num1 = document.getElementById("dividir").value;
    document.getElementById("resultado").value = num1 / 2;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>Número:<inputtype="text" onKeyUp="dividirNumero()" id="dividir" /> | Resultado: <input type="text" id="resultado"/>

This is a pretty basic concept of how you can do this calculation you are looking for, because every number you put in will find half of it. There are more complete codes to arrive at this result, but they are more complex.

I have you read in the Arithmetic Operators documentation for you to have an ample example of how you can be done too many operations with your code! :)

    
02.12.2018 / 20:35