for example in a drop down menu I would select two values ie 50 and 75 and they would combine as 5075, does this mean it is still running it through as string somewhere and if so where?
Yes, here:
objdeposited.value = parseInt(objDropDown.value+total);
objDropDown.value
is a string, e.g. '50'
, and total
is a number, e.g. 75
.
In JavaScript, '50'+75
is '5075'
.
You can replace these 3 lines
var total=parseInt(objdeposited.value);
objdeposited.value = parseInt(objDropDown.value+total);
objdeposited.value = parseInt(objdeposited.value);
with
var total = parseInt(objdeposited.value);
objdeposited.value = parseInt(objDropDown.value||'0') + total;
Edit:
The default value for the deposited
value was a space " "
which was causing problems. Change this to the empty string ""
. Also add a ||'0'
to all calls to parseInt (or parseFloat). See http://jsfiddle.net/es2yS/1/ .