jQuery/JavaScript: interrupt event?
<p>This is a really basic JavaScript question and probably duplicate, but I don't know the answer!</p>

<p>I have code as follows:</p>

<pre><code>function userlist_change(myval, function_type) {
   // relatively slow code involving Ajax call  
   // based on Ajax results, change some client-side stuff
}
$("#subjectlist").change(function() { 
    userlist_change($("#subjectlist").val(), 'change');
}).change(); 
$("#subjectlist").keypress(function() { 
    userlist_change($("#subjectlist").val(), 'keypress');
}); 
</code></pre>

<p>I have the problem that if the <code>.change()</code> event is called, the <code>userlist_change</code> function kicks off, and it's relatively slow. If the user changes the list again (e.g. by typing), my code waits for <code>userlist_change</code> to complete before restarting it with the new value.</p>

<p>This looks quite odd in the UI, as it can take a few seconds for anything to change client-side - and sometimes the results of the first call only appear after the user has already made a second call.</p>

<p>Is there any way I can interrupt any existing <code>userlist_change</code> process when the <code>.change()</code> or `keypress() event is fired?</p>

<p>[EDIT] What would be ideal is a simple 'kill any running functions with this name' command - is this possible? Or do I really have to fiddle around with timers?!</p>
