Craig McCoy

Programmer / Developer & Zombie Survivalist

Web Design

JQuery Make AJAX Call after user stops typing

Dec/2010 17

This should be a very straightforward example. We have an arbitrary JS function that we want to fire after a user stops typing in an input field. In my particular case, this is an AJAX email validation for Drupal, but the example can be applied to about anything.

[cc lang="javascript"]

$(document).ready(function() {
var inputTimer;
$("input#input_id").keyup(function() {
clearTimeout(inputTimer);
inputTimer = setTimeout(ajaxFunction, 1000); //fires after 1 second
});

});

Tags: 

Pages

Subscribe to RSS - Web Design