skip to Main Content

i have two input fields.
I have to divide one fields for the other

This is my javascript code

$("#circonferenza_vita").on("change",function(){
    var vita = $('#circonferenza_vita').val();
    var fianchi = $('#circonferenza_fianchi').val();
    alert(vita + " " + fianchi);
    var whr = (vita / fianchi);
    $('#whr').val(whr);
});

});

But when i insert the value in the input fields i have a wrong result.
For example if i insert vita 90 and fianchi 75 the result should be 0.8333 but i receive the result 1.2
Note that the alert return the correct values for vita and fianchi but the result is wrong.
Someone can help to understand and fix this issue? It is driving me crazy 🙂

3

Answers


  1. Chosen as BEST ANSWER

    Sorry, I inverted the variables in division. Thanks to all.


  2. Man, just swap your numbers, 90/75 = 1.2, that’s right. Have a good sleep then!

    Login or Signup to reply.
  3. Your Code is :

     var whr = (vita / fianchi);
    

    You said if i insert vita 90 and fianchi 75 the result should be 0.8333 but i receive the result 1.2. But it Should be 1.2 (90/75). Please Check your variables & Given Values.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search