Sum of two textfields - javascript

前端 未结 3 982
日久生厌
日久生厌 2021-01-20 15:55

I found [this][1], rather difficult, javascript example online and I\'ve implemented it with success in my website.

However, I would like to get the result of, in th

3条回答
  •  离开以前
    2021-01-20 16:40

    $("#value1, #value2").on('focusout', function() {
      var value2 = parseInt($("#value2").val()) > 0 ? parseInt($("#value2").val()) : 0;
      var value1 = parseInt($("#value1").val()) > 0 ? parseInt($("#value1").val()) : 0
      var sumOfValues = value1 + value2;
      console.log('Your sum is ' + sumOfValues);
    });
    
    
    

提交回复
热议问题