November 2, 2010
How to create a jquery timer that starts on keyup
Question by Josh R
I am using jquery 1.4. I want create the timer which starts on keyup event and resets on key press event. I want to use $.ajax request to send the time interval to the server. All I could find was countdown timers.
I appreciate any help.
Thanks
Answer by lonesomeday
You can do this very simply by comparing timestamps using native Javascript functions — no jQuery necessary for the timing logic:
var start, end, interval;
$('form' /*or whatever selector*/).keydown(function() {
start = new Date();
}).keyup(function() {
end = new Date();
interval = end.getTime() - start.getTime(); // interval in milliseconds
// do your AJAX here
});
Limit posting to every 30 minutes
Question by jay
Thanks for looking.
I’m trying to write a script to set a cookie after the user posts a comment, limiting them from posting again for 30 minutes. I’m so confused on where to start. Please, could you guys help me out on how I do this?
I’m trying to use this jquery plugin – countdown timer.
Answer by Starx
Use Session
For example, after a post, put the current time + 30 minutes in your session line this
$_SESSION['postTimeFlag'] = time() + 1800;
Then whenever the user is about to post then the session