Note that there are some explanatory texts on larger screens.

plurals
  1. PO(jquery/js) - get text from field on keyup, but with delay for further typing
    primarykey
    data
    text
    <p>Hey all. I have a form which is submitted remotely when the various elements change. On a search field in particular i'm using a keyup to detect when the text in the field changes. The problem with this is that when someone types "chicken" then the form is submitted seven times, with only the last one counting.</p> <p>What would be better is something like this</p> <ul> <li><p>keyup detected - start waiting (for one second)</p></li> <li><p>another keyup detected - restart waiting time</p></li> <li><p>waiting finishes - get value and submit form</p></li> </ul> <p>before i go off and code my own version of this (i'm really a backend guy with only a little js, i use jquery for everything), is there already an existing solution to this? It seems like it would be a common requirement. A jquery plugin maybe? if not, what's the simplest and best way to code this?</p> <p>thanks, max</p> <p>UPDATE - current code added for Dan (below)</p> <p>Dan - this may be relevant. One of the jquery plugins i'm using on the page (tablesorter) requires this file - "tablesorter/jquery-latest.js", which, if included, leads to the same error with your code as before:</p> <p>jQuery("input#search").data("timeout", null) is undefined <a href="http://192.168.0.234/javascripts/main.js?1264084467" rel="noreferrer">http://192.168.0.234/javascripts/main.js?1264084467</a> Line 11</p> <p>Maybe there's some sort of conflict between different jquery definitions? (or something)</p> <pre><code>$(document).ready(function() { //initiate the shadowbox player // Shadowbox.init({ // players: ['html', 'iframe'] // }); }); jQuery(function(){ jQuery('input#search') .data('timeout', null) .keyup(function(){ jQuery(this).data('timeout', setTimeout(function(){ var mytext = jQuery('input#search').val(); submitQuizForm(); jQuery('input#search').next().html(mytext); }, 2000) ) .keydown(function(){ clearTimeout(jQuery(this).data('timeout')); }); }); }); function submitQuizForm(){ form = jQuery("#searchQuizzes"); jQuery.ajax({ async:true, data:jQuery.param(form.serializeArray()), dataType:'script', type:'get', url:'/millionaire/millionaire_quizzes', success: function(msg){ // $("#chooseQuizMainTable").trigger("update"); } }); return true; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload