Link to home
Start Free TrialLog in
Avatar of Robert Granlund
Robert GranlundFlag for United States of America

asked on

Addition in Jquery

I am trying to do addition in JQuery but I'm not sure what I am doing:
baseOne = 1000;
baseTwo = 300
	var baseOne = document.getElementById('custom-price').value;  
        var baseTwo= document.getElementById('valueOfAccessories').valu);

        var preBase = baseOne + baseTwo;

Open in new window

For preBAse I get 1000300 instead of 1300.  What am I doing wrong?
Avatar of Gary
Gary
Flag of Ireland image

Assuming they are always integers else use parseFloat

var preBase = parseInt(baseOne) + parseInt(baseTwo);

Open in new window

you've a typo end of line 2, valu); -> value;
Avatar of Robert Granlund

ASKER

@Gary, when I do that it gives me 301.  It took the first three zeros off on 1000.
baseOne = 1000;
baseTwo = 300
var baseOne = document.getElementById('custom-price').value;  
 var baseTwo = document.getElementById('valueOfAccessories').value;

        var preBase = parseInt(baseOne) + parseInt(baseTwo);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland 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
SOLUTION
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