Link to home
Start Free TrialLog in
Avatar of Camillia
CamilliaFlag for United States of America

asked on

Javascript concats instead of adding

I have this Javascript code. The addition line doesnt add. It concats. For example, i have 2 values: 100.00 and 10.00 . It comes out as 10.00100.00

I googled and "+" is the right thing to use. Not sure why it's not adding:

<script type="text/javascript">
     var amount = 0.00;
     function prices(price) {


         var tempAmount = document.getElementById('<%=x_amount.ClientID %>');
         alert(tempAmount.value);
         amount = price + tempAmount.value;
         alert(amount);

         tempAmount.value = amount;
        // alert(amount.value);
   


     }
  </script>

Open in new window

Avatar of rsly
rsly
Flag of United States of America image

Try

amount = price + parseFloat(tempAmount.value);

Open in new window


http://www.w3schools.com/jsref/jsref_parsefloat.asp
Avatar of Camillia

ASKER

no, still comes out as this 10.00100
ASKER CERTIFIED SOLUTION
Avatar of rsly
rsly
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial