Solved

Jquery UI AutoComplete On Key Up

Posted on 2011-03-20
2
338 Views
Last Modified: 2012-05-11
hello-

I am using JqueryUI Auto Complete which works fine for simple things, however I need it to return values on every keystroke after the minimum entered. Right now, JqueryUI only returns the data from the first" minLength" entered. So what I need it do is:

Continue to hit my server with every key stroke after the minimum so the user continues to see the list change as they input text. Any help is appreciated.
<script>
	$(function() {
		var cache = {},
			lastXhr;
		$( "#addresses" ).autocomplete({
			minLength: 4,
			source: function( request, response ) {
				var term = request.term;
				if ( term in cache ) {
					response( cache[ term ] );
					return;
				}

				lastXhr = $.getJSON( "addresses.asp", request, function( data, status, xhr ) {
					cache[ term ] = data;
					if ( xhr === lastXhr ) {
						response( data );
					}
				});
			}
		});
	});

Open in new window

0
Comment
Question by:jfergy
2 Comments
 
LVL 9

Accepted Solution

by:
Vampireofdarkness earned 125 total points
ID: 35178497
The minLength variable will make it so that text of 0, 1, 2 and 3 characters long in the text box are not sent to autocomplete (ie- 'dog'); However, if you had 'dog bones' the entire thing would be sent as it is above four characters long.

You should be able to verify this is happening by adding an
alert(term);

Open in new window

after
var term = request.term;

Open in new window


I will note as well that you are creating the variable term, but sending the 'request' variable to addresses.asp. I am assuming one is the string (term) and one is an object / array.

0
 

Author Comment

by:jfergy
ID: 35182428
I understand whats happening now, what I need is the ability for it to continue to send what someone types in after the minlength. Right now it sends the Term to the json page as the min length but does not continue as someone types.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now