jQuery Autocomplete for multiple input fields
Hey guys, I've downloaded an auto-complete script in jQuery from formvega (http://www.fromvega.com) and I've encountered a problem. I want to make this work for several input fields and I've tried to make it work buy linking it to input classes. The problem is that when I do so it the first form fills all the other forms with the same content. I guess it's some problem with the variables in .js-file but I canät seem to figure out what it is.
Here is some code form the .js file:
var acListTotal = 0;
var acListCurrent = -1;
var acDelay = 500;
var acURL = null;
var acSearchId = null;
var acResultsId = null;
var acSear开发者_开发知识库chField = null;
var acResultsDiv = null;
function setAutoComplete(field_class, results_id, get_url ){
// initialize vars
acSearchId = "." + field_class;
acResultsId = "#" + results_id;
acURL = get_url;
// create the results div
$("body").append('<div id="' + results_id + '"></div>');
// register mostly used vars
acSearchField = $(acSearchId);
acResultsDiv = $(acResultsId);
// reposition div
repositionResultsDiv();
I don't see the actually code where you apply the autocomplete to a textbox. However I can assume it is similar to this.
<input type="text" class="auto-complete" />
<input type="text" class="auto-complete" />
<input type="text" class="auto-complete" />
.
$(".auto-complete").autoComplete({... options ...});
you would need to loop through them so they are set as their own scope
$texts = $(".auto-complete");
$.each($text, function(i, val) {
$(val).autoComplete({... options ...});
});
精彩评论