How can I mount a jquery to do this?
You can use a Event Handler of the kind input
or blur
, for example:
$("seletor_do_campo_taxa_de_venda").on("input ou blur", function(){
// ação
});
The input
will perform action as some value is inserted or removed from the field; the blur
when the field loses the phocus (the cursor leaves the field).
To carry out the division taxa_sale / real value_real the values of both fields must be of the number
. If fields are of type text
, you have to convert them to number
.
To play the value on the field total value, put in action the result of the division:
// se os campos forem tipo number
$("seletor_do_campo_taxa_de_denda").on("input ou blur", function(){
var total = $("seletor_do_campo_taxa_de_venda").val() / $("seletor_do_campo_valor_total").val();
$("seletor_do_campo_valor_total").val(total);
});
or
// se os campos forem tipo text com decimais separados por vírgula
$("seletor_do_campo_taxa_de_venda").on("input ou blur", function(){
var tx_venda = parseFloat($("seletor_do_campo_taxa_de_venda").val().replace(".","").replace(",","."));
var vl_total = parseFloat($("seletor_do_campo_valor_total").val().replace(".","").replace(",","."));
var total = tx_venda / vl_total;
$("seletor_do_campo_valor_total").val(total);
});
Obs.: if the element representing the total value be a div
, change $("seletor_do_campo_valor_total").val(total);
for $("seletor_do_campo_valor_total").text(total);
what you tried so far?
– Gabriel Santos