how to add multiple input value in javascript

Solutions on MaxInterview for how to add multiple input value in javascript by the best coders in the world

showing results for - "how to add multiple input value in javascript"
Elias
28 Oct 2016
1 $(document).ready(function(){
2
3    //iterate through each textboxes and add keyup
4    //handler to trigger sum event
5    $(".input-number").each(function() {
6
7        $(this).keyup(function(){
8            calculateSum();
9        });
10    });
11
12});
13
14function calculateSum() {
15
16    var sum = 0;
17    //iterate through each textboxes and add the values
18    $(".input-number").each(function() {
19
20        //add only if the value is number
21        if(!isNaN(this.value) && this.value.length!=0) {
22            sum += parseFloat(this.value);
23        }
24
25    });
26    //.toFixed() method will roundoff the final sum to 2 decimal places
27    $("#sum").html(sum.toFixed(2));
28}
29