I'd like to present another jQuery plugin, this time it's autocomplete with some handy features.
Description
The major benefit offered by this plugin is its high performance. As all request results are cached, the cache might be used next time, which leaves the server alone.
Besides, AutoComplete has some unique features, such as text separators, searching by a few words, and the optional using of the component autonomously, i.e. without sending requests to the server.
The plugin works in IE 6.0+, FF 2+, Safari 2.0+, Opera 9.0+, and Chrome 1.0+.
Installation
Installing the plugin is a routine task — just include the .js file after jQuery.
The autocomplete object is then initialized — make sure that initialization is duly done following the DOM loading, otherwise IE users might experience some glitches.
$('#query').autocomplete({
serviceUrl: 'service/autocomplete.ashx', // Page for processing autocomplete requests
minChars: 2, // Minimum request length for triggering autocomplete
delimiter: /(,|;)\s*/, // Delimiter for separating requests (a character or regex)
maxHeight: 400, // Maximum height of the suggestion list, in pixels
width: 300, // List width
zIndex: 9999, // List's z-index
deferRequestBy: 0, // Request delay (milliseconds), if you prefer not to send lots of requests while the user is typing. I usually set the delay at 300 ms.
params: { country: 'Yes'}, // Additional parameters
onSelect: function(data, value){ }, // Callback function, triggered if one of the suggested options is selected,
lookup: ['January', 'February', 'March'] // List of suggestions for local autocomplete
});
The page specified in serviceUrl receives a GET request, in response to which it must send JSON data:
{
query:'Li', // Original request
suggestions:['Liberia','Libyan Arab Jamahiriya','Liechtenstein','Lithuania'], // List of suggestions
data:['LR','LY','LI','LT'] // Optional parameter: list of keys for suggestion options; used in callback functions.
}
You can turn autocomplete on/off as well as re-initialize its parameters anytime via the object functions:
var ac = $('#query').autocomplete({ /*parameters*/ });
ac.disable();
ac.enable();
ac.setOptons({ zIndex: 1001 });
Stylization
The script makes the following tagged piece of code:
I am using php and tried to use this plugin but need your help on this
The page specified in serviceUrl receives a GET request, in response to which it must send JSON data:
{
query:'Li', // Original request
suggestions:['Liberia','Libyan Arab Jamahiriya','Liechtenstein','Lithuania'], // List of suggestions
data:['LR','LY','LI','LT'] // Optional parameter: list of keys for suggestion options; used in callback functions.
}
i tried to echo as text but it failed....the online documentation have no sufficient tutorials for beginner like me…
echo "{
query:'Li', // Original request
suggestions:['Liberia','Libyan Arab Jamahiriya','Liechtenstein','Lithuania'], // List of suggestions
data:['LR','LY','LI','LT'] // Optional parameter: list of keys for suggestion options; used in callback functions.
}"
To post a comment, you must be registered and logged in. Login or Register
Welcome to Splashnology
Splashnology is an exciting new platform for a Web community dedicated to Web Technology, with a focus on Web Design, Web Development, Gadgets, Graphic Design, Arts, Blogging, SEO, and Freelance. This site's primary purpose is to share Web-related knowledge, resources, and ideas. Anyone — including you — can become an author at Splashnology and post things that might be of interest to our community in personal or general blogs. We love what we do!
We are looking for writers. If you are interested in writing exclusive articles for Splashnology please contact us. Also you can submit any article into your personal blog.
Comments (2)
RSS Collapse / ExpandI am using php and tried to use this plugin but need your help on this
The page specified in serviceUrl receives a GET request, in response to which it must send JSON data:
{
query:'Li', // Original request
suggestions:['Liberia','Libyan Arab Jamahiriya','Liechtenstein','Lithuania'], // List of suggestions
data:['LR','LY','LI','LT'] // Optional parameter: list of keys for suggestion options; used in callback functions.
}
i tried to echo as text but it failed....the online documentation have no sufficient tutorials for beginner like me…
echo "{
query:'Li', // Original request
suggestions:['Liberia','Libyan Arab Jamahiriya','Liechtenstein','Lithuania'], // List of suggestions
data:['LR','LY','LI','LT'] // Optional parameter: list of keys for suggestion options; used in callback functions.
}"
loonyew
Try to use it without PHP, just JavaScript. You need check JS, if it work it's mean the problem in PHP.
Timmay
To post a comment, you must be registered and logged in. Login or Register