gerkintrigg Posted February 6, 2009 Share Posted February 6, 2009 hello. I'm trying to change the total when I click on the button on this page: http://magic2k.com/gd2/shop_cart_add.php?prod=4 I want to add 6 to the value of the text, but it just says "NaN", which I understand to mean that I am mixing text and number elements. So how can I make the existing text within the span element an integer? Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/144073-adding-int-to-text/ Share on other sites More sharing options...
Psycho Posted February 6, 2009 Share Posted February 6, 2009 I would really suggest making a function for this instead of putting the JS inline. Anyway, you have multiple problems: 1. A SPAN does not have a value. You need to use innerHTML to get the current value 2. You need to "cast" the value as a number so it doesn't get interpreted as text. Use parseFloat(). Try this onClick="document.getElementById('total').innerHTML = (parseFloat(document.getElementById('total').innerHTML) + 6);" Link to comment https://forums.phpfreaks.com/topic/144073-adding-int-to-text/#findComment-756057 Share on other sites More sharing options...
gerkintrigg Posted February 6, 2009 Author Share Posted February 6, 2009 Thanks ever-so-much. I will put all of this stuff into a function later, but for now just need to make it work. Link to comment https://forums.phpfreaks.com/topic/144073-adding-int-to-text/#findComment-756099 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.