solarisuser Posted May 30, 2007 Share Posted May 30, 2007 I have <div id=field_50>7000</div> and when I run the JS code below, it doesn't add 80, but appends 80 to 7000. Also, after it does that, it redirects to another page, but I'm assuming its because of a JS error maybe? function update(i){ var oldone=document.getElementById('field_' + i).innerHTML; document.getElementById('field_' + i).innerHTML = ''; oldone+= 80; document.getElementById('field_' + i).innerHTML = oldone; } This is called from an <A onclick=update(50);> and works, I used alert() to show that i is being seen (50 in this case).... Thanks in advance! Quote Link to comment Share on other sites More sharing options...
nogray Posted May 31, 2007 Share Posted May 31, 2007 This happens because the innerHTML returns a string not a number, you can use one of these functions to convert the innerHTML to a number before doing the math oldone = parseFloat(oldone); // for float numbers oldone = parseInt(oldone); // for integers Quote Link to comment Share on other sites More sharing options...
solarisuser Posted June 1, 2007 Author Share Posted June 1, 2007 Thanks - That did it! 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.