Solved

Jquery UI AutoComplete On Key Up

Posted on 2011-03-20
2
337 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

743 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

10 Experts available now in Live!

Get 1:1 Help Now