JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" value="1,000" id="input_one" size="10" />
<strong>+</strong>
<input type="text" value="1,000" id="input_two" size="10" />
<strong>=</strong>
<input type="text" value="2,000" id="sum" size="10" />
<input type="button" id="submit" value="Add it!" />
JavaScript
$("#submit").click( function() {
var value_one = $("#input_one").val();
var value_two = $("#input_two").val();
var value_one_int = parseInt( $("#input_one").val().replace(',', ''), 10 );
var value_two_int = parseInt( $("#input_two").val().replace(',', ''), 10 );
var sum = value_one_int + value_two_int;
$("#sum").val( addCommas(sum) );
});
function addCommas(nStr)
{
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}