Jump to content

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

My Javascript is a little rusty, but try something like this:

 


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

function increase() {
counter++;

return false;
}
</script>

<input type="submit" value="Add Click" onclick="increase()" />

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>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.