dreamwest Posted March 17, 2011 Share Posted March 17, 2011 Im trying to get an innerhtml value to increment by 1 <script> function up(){ document.getElementById("cnt").innerHTML = document.getElementById('cnt') + 1; } </script> <span id='cnt'>0</span> <span style='cursor:pointer;' onclick='up(); '>Go up</span> Link to comment https://forums.phpfreaks.com/topic/230901-innerhtml/ Share on other sites More sharing options...
gristoi Posted March 17, 2011 Share Posted March 17, 2011 the innerHTML needs converting into an Integer / Float etc before a mathimatical function can be performed. Try: <script> function up(){ var field = document.getElementById("cnt").innerHTML; var value1 = parseInt(field); document.getElementById("cnt").innerHTML =value1 +1; } </script> <span id='cnt'>0</span> <span style='cursor:pointer;' onclick='up(); '>Go up</span> Link to comment https://forums.phpfreaks.com/topic/230901-innerhtml/#findComment-1188649 Share on other sites More sharing options...
dreamwest Posted March 17, 2011 Author Share Posted March 17, 2011 sweet! Thanks Link to comment https://forums.phpfreaks.com/topic/230901-innerhtml/#findComment-1188877 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.