Jump to content

Please Help With Simple Counter


realife

Recommended Posts

Hello PHP...

 

Let's say i have a button, and below that i have a number which counting the clicks on the button, for example

 

<input type="submit" value="Add Click" />  <br>
So far = 12 Clicks

 

How can i set it that onclick it will add more to the number ( of course without refreshing the page ) ?

Link to comment
https://forums.phpfreaks.com/topic/270856-please-help-with-simple-counter/
Share on other sites

That is not exactly what you wrote. ;-)

 


<script type="text/javascript">
var counter = 0;

function increase() {
counter++;

document.getElementById('click_count').innerHTML = 'You have clicked ' + counter + ' times.';

return false;
}
</script>

<input type="submit" value="Add Click" onclick="increase()" />
<div id="click_count">You have clicked 0 times.</div>

You are welcome. You could do like this:

 


<script type="text/javascript">
var counter = 0;

function increase() {
if (counter < 1) {
counter++;

document.getElementById('click_count').innerHTML = 'You have clicked ' + counter + ' times.';
}

else {
document.getElementById('click_count').innerHTML = 'You are not allowed to click anymore.';
}

return false;
}
</script>

<input type="submit" value="Add Click" onclick="increase()" />
<div id="click_count">You have clicked 0 times.</div>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.