Take this number "#1"
Make it turn to a "#2" in 5 seconds
Then to a "#3" in 5 seconds
Is this possible, or how do i accomplish this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because PHP executes on the server and only sends the resulting output to the browser, we can’t use only PHP to update it.
Easiest method would be to use JavaScript’s
setTimeoutmethod.The update function gets called once on the body’s load and then it calls itself after 1000ms to make a 1 second counter. Note: I have to multiply the
innerTextby 1 to convert a string to a number so it will add instead of concatenating.Another way of doing this, although I don’t know why you’d want to do it this way (but it uses PHP.. lol) is to refresh the page with an updated query string parameter.
Here I get the current value of the counter and add 1 using PHP and then echo a meta refresh tag to, after 1 second, refresh the page with the updated count value in the query string. Next time the page loads, it’ll read that value, add one, refresh with the new value, etc. This is just to show you another way, I would not recommend doing this in your application!