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~ Link to comment https://forums.phpfreaks.com/topic/103246-adding-2-numbers/ 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 Link to comment https://forums.phpfreaks.com/topic/103246-adding-2-numbers/#findComment-528986 Share on other sites More sharing options...
everisk Posted May 2, 2008 Author Share Posted May 2, 2008 oh thanks! Link to comment https://forums.phpfreaks.com/topic/103246-adding-2-numbers/#findComment-531632 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; Link to comment https://forums.phpfreaks.com/topic/103246-adding-2-numbers/#findComment-536999 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.