How to calculate using onblur between 3 fields

Asked

Viewed 60 times

1

I have three fields in a form. Putting the value in one, when leaving this field, lavascript should do the calculation and popular the other two each with a result:

EX:

Campo 1: Entro com o valor 10
Ao sair do campo 1, deve fazer
Campo 2 = Campo1 * 10 / 100
Campo 3 = Campo1 * 20 / 100

Has as?

1 answer

0


With jquery speeds up the process...

$(document).ready(function(){
                $('.input1').blur(function(e){
                    var inp1 = $(this).value;

                    var inp2 = (inp1 * 10)/100;
                    var inp3 = (inp1 * 20)/100;

                    $('.input2').val(desconto);
                    $('.input3').val(total);
                })
            })
  • OK. Solved. Obg.

  • $(this).value; should be $(this).val() and would be better to convert to type Number.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.