SO - 20342169

by Arun P Johny

HTML

Shipping: <input type="text" class="input-small fee" name="ship_fee" id="ship-fee">

Other: <input type="text" class="input-small fee" name="other_fee" id="other-fee">
    
<div>
$ <span id="total" data-total="50"><p></p></span>
</div>

JavaScript

//use the class-selector .fe because fee is the class attribute
var $fees = $('.fee').change(function(){
    var total = 0;
    //iterate through all the fee elements and find the total
    $fees.each(function(){
        total += (parseFloat($.trim(this.value)) ||0)
    })
    $( "p" ).text( total.toFixed(2) );
});