everisk Posted April 28, 2008 Share Posted April 28, 2008 Hi, I'm very new to Javascript and found a very strange behaviour when trying to add 2 numbers. DOnt know if i got everything right. Below is my code. price = document.getElementById("price").value; vat_p = (price*0.07)+price; document.getElementById("price").value=vat_p; Instead of adding (price*0.07) to price, price was appended to the result of (price*0.07).Help please~ Quote Link to comment Share on other sites More sharing options...
nogray Posted April 28, 2008 Share Posted April 28, 2008 use parseInt() price = parseInt(document.getElementById('price').value, 10); this will make sure the input is converted into an integer Quote Link to comment Share on other sites More sharing options...
everisk Posted May 2, 2008 Author Share Posted May 2, 2008 oh thanks! Quote Link to comment Share on other sites More sharing options...
epic_era1 Posted May 9, 2008 Share Posted May 9, 2008 you could try this too price*=1; vat_p = (price*0.07)+price; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.