[jQuery] Re: how to delay a event?
are u trying to achieve something like autocomplete (like google suggest), if that is the case, then you should look at http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/ -GTG On 8/22/07, james_027 [EMAIL PROTECTED] wrote: hi, I have a small jQuery script, that get some data over the server on every keypress by the user, but I don't to perform such action every time when the user presses a key, specially if between key presses happens in short amount of time. How do I delay this event? Here is my script $('[EMAIL PROTECTED]').keyup(function(e){ if (e.target.value != ''){ $.get('/main/search_item/', {search_item:e.target.value }, function(data){ $('[EMAIL PROTECTED]').html(data); } ); } }); thanks james
[jQuery] Re: how to delay a event?
Hi, On Aug 23, 2:34 pm, Ganeshji Marwaha [EMAIL PROTECTED] wrote: are u trying to achieve something like autocomplete (like google suggest), if that is the case, then you should look athttp://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/ -GTG No I am doing a auto complete here... THanks james
[jQuery] Re: how to delay a event?
sorry, am i missing something. -GTG On 8/22/07, james_027 [EMAIL PROTECTED] wrote: Hi, On Aug 23, 2:34 pm, Ganeshji Marwaha [EMAIL PROTECTED] wrote: are u trying to achieve something like autocomplete (like google suggest), if that is the case, then you should look athttp://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/ -GTG No I am doing a auto complete here... THanks james
[jQuery] Re: how to delay a event?
I think he wants to delay the keyup event but i don't think you can't delay that because it's the trigger for the actions. -- David Ganeshji Marwaha schreef: sorry, am i missing something. -GTG On 8/22/07, *james_027* [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Hi, On Aug 23, 2:34 pm, Ganeshji Marwaha [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: are u trying to achieve something like autocomplete (like google suggest), if that is the case, then you should look athttp://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/ -GTG No I am doing a auto complete here... THanks james No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.484 / Virus Database: 269.12.1/965 - Release Date: 21/08/2007 16:02 -- David Duymelinck [EMAIL PROTECTED]
[jQuery] Re: how to delay a event?
Check out my response to this question when it came up back in March: http://www.mail-archive.com/[EMAIL PROTECTED]/msg18931.html Hope it helps. --Erik On 8/22/07, james_027 [EMAIL PROTECTED] wrote: hi, I have a small jQuery script, that get some data over the server on every keypress by the user, but I don't to perform such action every time when the user presses a key, specially if between key presses happens in short amount of time. How do I delay this event? Here is my script $('[EMAIL PROTECTED]').keyup(function(e){ if (e.target.value != ''){ $.get('/main/search_item/', {search_item:e.target.value}, function(data){ $('[EMAIL PROTECTED]').html(data); } ); } }); thanks james
[jQuery] Re: how to delay a event?
james_027 wrote: hi, I have a small jQuery script, that get some data over the server on every keypress by the user, but I don't to perform such action every time when the user presses a key, specially if between key presses happens in short amount of time. How do I delay this event? Here is my script $('[EMAIL PROTECTED]').keyup(function(e){ if (e.target.value != ''){ $.get('/main/search_item/', {search_item:e.target.value}, function(data){ $('[EMAIL PROTECTED]').html(data); } ); } }); thanks james var delayed; $('[EMAIL PROTECTED]').keyup(function() { clearTimeout(delayed); var value = this.value; if (value) { delayed = setTimeout(function() { $.get('/main/search_item/', { search_item: value }, function(data) { $('#search_item_result]').html(data); }); }, 400); } }); I've optimized a few things as well, like using the faster #id selector and using this instead of e.target... --Klaus
[jQuery] Re: how to delay a event?
Klaus Hartl wrote: var delayed; $('[EMAIL PROTECTED]').keyup(function() { clearTimeout(delayed); var value = this.value; if (value) { delayed = setTimeout(function() { $.get('/main/search_item/', { search_item: value }, function(data) { $('#search_item_result]').html(data); }); }, 400); } }); There's a typo, use $('#search_item_result').html(data); --Klaus