Solved

Jquery UI AutoComplete On Key Up

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…
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

751 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