0
Good afternoon, I have a question related to creating a function for generic use in javascript, the function is this here:
function calcular() {
var_quant = 0;
var valor = document.getElementById("valor").value;
var quantidade = document.getElementById("quantidade").value;
var quantidade_devolvida =
document.getElementById("quantidade_devolvida").value;
if (quantidade_devolvida <= quantidade) {
var var_quant = valor * quantidade_devolvida;
document.getElementById("var_qnt").value = var_quant;
}
}
I need to turn this function into a function that works in any input. Please if anyone could help me I really appreciate it.
Daniel, is quantity always fixed? It would be interesting to show the structure of these inputs to know what varies and what is fixed. And how you’re calling this function
calcular
, is by clicking button?– Sam
It occurs in the input of the final result itself by an onChange, but these values, quantity, quantity_returned and value, come from a json.
– Daniel Rezende