Validate various inputs

-1

I have the following question: for example in my order form I want to do this: I have an input where I enter the amount of services eg 1,2,3,4 etc. in another the price and through another would like to set the tax and in another show the price with tax but I would like to know if it can be done automatically, that is, when entering the amount is multiplied by the price more the tax and it is shown automatically in the last input that is to say it would have 4 inputs. Greetings, I hope you can help me.

    
asked by Pedro Agostini 25.11.2018 в 13:27
source

1 answer

0

I think with something like that you could leave

    Servicios: <input type="text" id="services" value="1" onchange="makeCalcs()"/><br>
    Precio: <input type="text" id="price" value="0" onchange="makeCalcs()"/><br>
    Impuesto: <input type="text" id="iva" value="21" onchange="makeCalcs()"/><br>
    Total: <input type="text" id="total" value="0"/><br>

    <script>
        function makeCalcs() {
            var services = document.getElementById("services").value;
            var price = document.getElementById("price").value;
            var iva = document.getElementById("iva").value;

            document.getElementById("total").value = services * price + (iva / 100 * (services * price));
        }
    </script>

It's pretty simple every time you edit one of the fields the last one will be updated with the necessary information, you can add more things to it that are not allowed to use characteres / letters so that only numbers are used. But in principle he would do his job.

    
answered by 25.11.2018 / 15:38
source