Results 1 to 3 of 3

Thread: Can't add innerText values?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2005
    Posts
    27

    Can't add innerText values?

    Hello,
    My innerText values are concatenating instead of added. Any ideas?

    Thanks!

    Code:
    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));

  2. #2
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: Can't add innerText values?

    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

    If I have been helpful please rate my post. If I haven't tell me!

  3. #3
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Can't add innerText values?

    try this:

    Code:
    <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
    My Blog.

    Ryan Jones.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width