PDA

Click to See Complete Forum and Search --> : Can't add innerText values?


broadvision123
May 19th, 2005, 10:50 AM
Hello,
My innerText values are concatenating instead of added. Any ideas?

Thanks!


var txtQtyBox = document.getElementById("txtPrinterQuantity2");
var lblPriceBox = document.getElementById("lblPrinterAmount2");
var lblPriceBoxb = document.getElementById("lblPrinterAmount2b");
var lblPriceBoxc = document.getElementById("lblPrinterAmount2c");

OOTotal += (txtQtyBox.value * (lblPriceBox.innerText+lblPriceBoxb.innerText+lblPriceBoxc.innerText));

dj4uk
May 19th, 2005, 11:06 AM
As they are innerText they are strings not numerical values - you need to convert them to the numeric type you need before adding. + used with strings just concatenates!

DJ

sciguyryan
May 19th, 2005, 12:01 PM
try this:


<script type="text/javascript">
<!--
var txtQtyBox = document.getElementById("txtPrinterQuantity2");
var lblPriceBox = document.getElementById("lblPrinterAmount2");
var lblPriceBoxb = document.getElementById("lblPrinterAmount2b");
var lblPriceBoxc = document.getElementById("lblPrinterAmount2c");

OOTotal += (eval(txtQtyBox.value) * (eval(lblPriceBox.innerText) + eval(lblPriceBoxb.innerText) + eval(lblPriceBoxc.innerText)));
//-->
</script>


Cheers,

RyanJ