0

JavaScript is adding numbers 7 and 11 and getting 711, not 18 like it should be. Has to be dynamic which is why I'm using getElementByID. In this sample Hardcopy = 7 ElectronicCopy = 11. Here is the sample code.

var TotalSites = document.getElementById("TotalSites").innerHTML;
var HardCopy = document.getElementById("ImagingMaterialsHardCopy").innerHTML;
var ElectronicCopy = document.getElementById("ImagingMaterialsElectronic").innerHTML;
var LTR = HardCopy + ElectronicCopy;
var LefttoRec = LTR - TotalSites;
j08691
  • 204,283
  • 31
  • 260
  • 272
Jason Sprague
  • 75
  • 1
  • 9
  • You need to parseInt or parseFloat the values coming from the page - they are considered as strings this the concatenation of the values. –  May 30 '17 at 15:54
  • You are performing string concatenation instead of adding numbers. Convert to `number` first, e.g. via `var TotalSites = +document...` – le_m May 30 '17 at 15:54
  • When you add 7 and 11 and get 711 you're concatenating strings, not dealing with numbers. Try explicitly converting them. – j08691 May 30 '17 at 15:54

0 Answers0