Javascript setTimeout and rails :onkeyup
===

I'm having an interesting problem.
I have the following code in my partial which displays a list based on substring entered in the text field

    <%= form_for :subString_typed, :controller => "deployment_group", :remote=> true, :method => "get", :url => {:action => "show_workflow_list"}, :html => {:id => "subString_form"} do |f| %>
    				<%= f.label :Substring %> <%= f.text_field :subString, :onkeyup => "show_alert()" %>
    				<%end%>

And the show_alert() function is:

    function show_alert()
    	{
    		$("#subString_form").submit();
    	}
    	
Now, iam able to type no more than two or three letters in the substring text field above, and the list is displayed immediately. Hence i want to pause the function before executing and so i changed it as:
function show_alert()
	

		{  
				setTimeout(function(){$("#subString_form").submit()}, 2000);
			}
Now im able to type a long string say "index" and the list displays all the lines that have the word index initially. But, this is the data that is sent to my server:

      Parameters: {"utf8"=>"Γ£ô", "subString_typed"=>{"subString"=>"index"}, "select
    ed_folder"=>"RISK_ODS"} at 14:00:39
      Parameters: {"utf8"=>"Γ£ô", "subString_typed"=>{"subString"=>"index"}, "select
    ed_folder"=>"RISK_ODS"} at 14:00:39
      Parameters: {"utf8"=>"Γ£ô", "subString_typed"=>{"subString"=>"index"}, "select
    ed_folder"=>"RISK_ODS"} at 14:00:39
      Parameters: {"utf8"=>"Γ£ô", "subString_typed"=>{"subString"=>"index"}, "select
    ed_folder"=>"RISK_ODS"} at 14:00:40
      Parameters: {"utf8"=>"Γ£ô", "subString_typed"=>{"subString"=>""}, "select
    ed_folder"=>"RISK_ODS"} at 14:00:40

Since each onkeyup is counted and index has five :onkeyup, the javascript code is executed five times? and by the time it executes for the fifth time, there is nothing in the current textfeild at 14:00:40 and hence the lines which have 'index' are displayed at 14:00:39 and then again the entire list is displayed at 14:00:40

How can i appraoch to solve this problem? And one more thing is that i do not see this problem when i do not use setTimeout. When i do not use i see the following

    Parameters: {"utf8"=>"Γ£ô", "subString_typed"=>{"subString"=>"i"}, "select
        ed_folder"=>"RISK_ODS"} 
          Parameters: {"utf8"=>"Γ£ô", "subString_typed"=>{"subString"=>"in"}, "select
        ed_folder"=>"RISK_ODS"} 
          Parameters: {"utf8"=>"Γ£ô", "subString_typed"=>{"subString"=>"ind"}, "select
        ed_folder"=>"RISK_ODS"} 
          Parameters: {"utf8"=>"Γ£ô", "subString_typed"=>{"subString"=>"inde"}, "select

and the list related to 'inde' is being displayed 

