• javascript live count on click
    3 replies, posted
I have a number on the top of the page that i want to increase when a button is clicked. Let's say the number is 3, when the press the button I want the number that's already in the html to be noticed, and have one added to it. This is my text at the top, [html]<li><a href="#"><span id="awn">3</span> Problems</a></li> [/html] I figured something like this would help? (I'm not GREAT at javascript. [html]<script>document.getElementById('awn').value='';</script>[/html] I want it to take the contents, count up, and replace, I figure an onclick would work for this.
document.getElementById( 'awn' ).innerHTML will return the number. Make sure you force it to be an int though.
document.getElementById( 'awn' ).innerHTML = Math.round(document.getElementById( 'awn' ).innerHTML) + 1;
[QUOTE=h2ooooooo;21353440]document.getElementById( 'awn' ).innerHTML = Math.round(document.getElementById( 'awn' ).innerHTML) + 1;[/QUOTE] Perfect, thanks so much.
Sorry, you need to Log In to post a reply to this thread.