<head>
<meta charset="utf-8">
</head>
<body>
left:<input type="text" id="left" />
<br/>right:
<input type="text" id="right" />
<button id="summ">Сложить</button>
<br/>sum: <span id="sum"></span>
<script>
document.getElementById("summ").addEventListener("click", function(e) {
var left = document.getElementById('left').value;
var right = document.getElementById('right').value;
if(isNaN(left) || isNaN(right)) return;
document.getElementById('sum').innerHTML = (add(left,right));
});
function res(a, b, result, carry, base) {
if (a.length == 0 && b.length == 0 && !carry)
return result;
var left = parseInt(a.pop() || '0', 10);
var right = parseInt(b.pop() || '0', 10);
var l = left + right + (carry || 0);
return res(a, b, l % base + (result || ""), Math.floor(l / base), base);
}
function add(a, b) {
return res(a.toString().split(""), b.toString().split(""), "", "", 10).toString();
}
</script>
</body>
если вам только для сложения