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. Quote Link to comment 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);" Quote Link to comment 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. 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.