Solved

Jquery UI AutoComplete On Key Up

Posted on 2011-03-20
2
342 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

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…
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…
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

623 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