Selacius Posted December 9, 2005 Share Posted December 9, 2005 I want to allow the user to press a link and/or a button which in turn will increase the count of a value previously displayed on a webpage. How can I go about displaying the new value without refreshing the page? Link to comment Share on other sites More sharing options...
aspnetguy Posted December 9, 2005 Share Posted December 9, 2005 Try this <html><head><script>function increment(targetId){ var targetElement = document.getElementById(targetId); if(isNaN(targetElement)) { alert('Can't increment. Value is not a number!'); } else { targetElement.innerHTML = parseInt(targetElement.innerHTML) + 1; }}</script></head><body><div id="counter">5</div><div><a href="javascript:void(0)" onclick="increment('counter')">Click Me</a></div></body> Hope this works for you...let me know if it doesn't. Link to comment Share on other sites More sharing options...
Selacius Posted December 9, 2005 Author Share Posted December 9, 2005 Didn't change the displayed value from 5 to 6. THis is exactly what I want to do, but on a larger scale with 4 or so variables. Link to comment Share on other sites More sharing options...
Chocolate570 Posted December 9, 2005 Share Posted December 9, 2005 Hmm...try this then? <script type="text/javascript">function goThing(who) {x=document.getElementById(who).value;if(isNaN(x)){alert("Not a number, can not continue.")return;}eval("x+1")}</script> Link to comment Share on other sites More sharing options...
aspnetguy Posted December 10, 2005 Share Posted December 10, 2005 good catch...I didn't even think of the eval function. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now