I am using the following function (With help from Paul Wilkins) to refresh dynamic loaded content every 10 seconds:
$(function () {
var timer,
updateContent;
function resetTimer() {
if (timer) {
window.clearTimeout(timer);
}
timer = window.setTimeout(updateContent, 10000);
}
updateContent = function () {
resetTimer();
$.get('modules/berichten.php', function (data) {
$('#main').html(data);
});
};
updateContent();
$(document.body).on('mousemove keydown', resetTimer);
});
The timer will be reset when there is mouse movement or when there are key strokes. I was wondering if it is possible to reset the timer when a certain textfield or text area is in focus?
You can’t listen to focus on a form element. Instead you should listen to focus events on the children within that form. So $(‘#bericht_form :input’) instead of $(‘#bericht_form’) in your code should work.
In case you’re wondering, :input selects all input, textarea, select and button elements.
(copied verbatim from the manual)