0

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 acSearchField = 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();

1 Answer 1

1

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 ...});
});
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for the answer The code is: $(function(){ setAutoComplete("searchField", "results","autocomplete2.php?part=" ); }); <input type="text" class="searchField" /> <input type="text" class="searchField" /> Can I still use your code suggestion?
I updated your question, but I still don't see the actual call when you attach the autocomplete to a textbox?
Bobby, I'm quite a noob at this stuff. The call is: <input class="searchField" name="departfrom" id="searchField" required="required" type="text" title="Where are you departing from?">. The form input class should be the call, right?
Okey! Found a better way of making this work. Trial and error!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.