I have a similar feature in one of my windows applications. When the user types a character, a timer is started with a 1 second interval. In the Tick event, the search is started. If the user types again, the timer is restarted. So the search is only performed if the keyboard has been idle for more than a second.
Short sample (it's in C#, but easy enough to follow):
public partial class Form1 : Form
{
private System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
public Form1()
{
InitializeComponent();
timer.Interval = 1000;
timer.Tick += new EventHandler(timer_Tick);
}
void timer_Tick(object sender, EventArgs e)
{
timer.Stop();
// Do search, or what ever you want to do
Console.WriteLine("Searching...");
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (timer.Enabled)
{
timer.Stop();
}
timer.Start();
}
}
I'm not experienced in Javascript, but the anwswer from here will help you I think:
<input name="domain" type="text" id="domain" onKeyUp="javascript:chk_me();">
var timer;
function chk_me(){
clearTimeout(timer);
timer=setTimeout(function validate(){...},1000);
}