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! Link to comment https://forums.phpfreaks.com/topic/53650-solved-what-is-wrong-with-this/ 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 Link to comment https://forums.phpfreaks.com/topic/53650-solved-what-is-wrong-with-this/#findComment-265711 Share on other sites More sharing options...
solarisuser Posted June 1, 2007 Author Share Posted June 1, 2007 Thanks - That did it! Link to comment https://forums.phpfreaks.com/topic/53650-solved-what-is-wrong-with-this/#findComment-265946 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.