spires Posted August 25, 2009 Share Posted August 25, 2009 Hi guys. I'm doing a a simple equation, all I want to do is add to value together. However, instead of adding the are concatenating. Both value are numeric so it should work fine, when I replace the variable with a static numeric number it works fine. but when I use the variable it keeps concatenating. Any ideas? My Code: var joinedProduct=productarray[1]+productarray[2]; alert(joinedProduct); productarray[1] = 60 productarray[2] = 60 output = 6060 not = 120 Thanks Link to comment https://forums.phpfreaks.com/topic/171749-my-strings-keep-concatenating-not-adding-together/ Share on other sites More sharing options...
haku Posted August 25, 2009 Share Posted August 25, 2009 They are both numeric, but that doesn't mean that javascript sees them as numbers. It is seeing them as text. Use this: var joinedProduct= Number(productarray[1]) + Number(productarray[2]); It should solve your problem. Link to comment https://forums.phpfreaks.com/topic/171749-my-strings-keep-concatenating-not-adding-together/#findComment-905661 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.