Home > database >  jQuery script not showing equation result
jQuery script not showing equation result

Time:10-19

I am working on a script to calculate some stuff using multiple input. I have been copy-pasting my script because it has been working for 2 values calculations. For example:

        //Diameter Pitch
                $(document).ready(function(){
$('input[type="text"]').keyup(function () {
  var valM = parseInt($('.dpModule').val());
  var valZ = parseInt($('.dpJumlahGigi').val());
          var sum = valZ*valM;
          $("input#resultDP").val(sum);
});
});

But now I am trying to add another variable Phi (3.14) but the calculation is not working

    //Circular Pitch
        $(document).ready(function(){
$('input[type="text"]').keyup(function () {
  var valD = parseInt($('.cpPitchDiameter').val());
  var valT = parseInt($('.cpAot').val());
    var phi = parseInt($('3.14').val());
          var sum = phi*valD/valT;
          $("input#resultCP").val(sum);
});
});

The circular pitch script resulted with NaN, can anyone please fix my code? I am trying to make the following formula:

var sum = 3.14*valD/valT;

Much thanks in advance

CodePudding user response:

Replace: var phi = parseInt($('3.14').val()); with var phi = 3.14;.

Your current code is trying to look for a '3.14'tag in your HTML so it returns "not a number" since that doesn't exist in the HTML.

  • Related