jQuery Sum & Subtract Two Input Fields Values

Demo Download

In this tutorial I will explain how to add & subtract two input fields values using jQuery. This is very simple tutorial, you just need to write HTML and jQuery to achieve it.

Note: Don’t forget to include the jQuery library in the header or footer of web page.

The HTML

As you can see above we will add Num 1 and Num 2 and display their result on Sum, and subtract Num 2 from Num 1.

The jQuery

If you find this tutorial helpful so share it with your friends and leave your comment.

Article By
Javed Ur Rehman is a passionate blogger and web developer, he loves to share web development tutorials and blogging tips. He usually writes about HTML, CSS, JavaScript, Jquery, Ajax, PHP and MySQL.

8 Comments

  1. Why in my form its showing rounding off

    $(function() {
    $(“#fparkingamount, #ftollamount”).on(“keydown keyup”, sum);
    function sum() {
    $(“#ftotclaimamount”).val(Number($(“#fparkingamount”).val()) + Number($(“#ftollamount”).val()));
    }
    });

    fparkingamount 8.20
    ftollamount 2.20
    ftotclaimamount 10.399999?

    1. Well i checked it is showing 10.399999999999999 if i enter the same value as you mentioned above.
      If you want to get the round value then you can use.

      (10.399999999999999).toFixed(2);

      It will give you 10.39

  2. Wow i used this and it is working @ thank you so much , i have used to subtract to input number and the result gives me NaN but this working Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *