You're Doing It Wrong
For starters.
function addBills(){
var
hundreds = parseInt($("#input100").innerHTML(),10)*100;
hundreds
is the only local var. All others are global. Fix: use comma's instead of semicolons to separate variables in one var-statement.
Secondly inputfields have a value
(not innerHTML
, and especially not innerHTML()
as a function).
inputfields values are always text. One can convert them to numbers by either Number(string)
or parseInt(string, radix/base)
(or adding a +
in front of the string).
Finally, once you have the span-element you thus simply do: elm_span.innerHTML=yourNumber;
and bob's your uncle!
EDIT:
Your current loop makes no sense.. I mean, if regTotal
is the total of the cash... and you have one span with the unique id totalCount
... it's completely pointless (just as trying to convert the totalCount
to string a couple of thousands of times)
You probably want something like:
function addBills(){
var hundreds = Number(document.getElementById('input100').value)*100
, fifties = Number(document.getElementById('input50').value)*50
, twenties = Number(document.getElementById('input20').value)*20
, tens = Number(document.getElementById('input10').value)*10
, fives = Number(document.getElementById('input5').value)*5
, ones = Number(document.getElementById('input1').value)
, regTotal = hundreds+fifties+twenties+tens+fives+ones
; //end local
document.getElementById('totalCount').innerHTML=regTotal;
}
Working example fiddle here
Hope this helps!