1

I have this code working, from this example:

var url = function(req, res){
    $.ajax({
        url: "getdata",
        dataType: "json",
        data: {
            term: req.term,
        },
        success: function(data){
            res($.map(data.students, function(item){
            return{
                label: item.cardId + "|" + item.firstName + " " + item.lastName,
                value: item.cardId
            }}))
        }
    });
};


$("#autocomplete").autocomplete({
    source: url
});
$("#autocomplete2").autocomplete({
    source: url
});

And input elements:

<input path="students" id="autocomplete" style="z-index: 100; position: relative" title="type &quot;a&quot;" autofocus="autofocus" />
<input path="items" id="autocomplete2" style="z-index: 100; position: relative" title="type &quot;a&quot;" />


Both inputs have now the same dropdown list.

Question:
How to change url function to fit students and items? Or should just copy function for each type of input?

1 Answer 1

4

Inside your url function, this.element will give you the element which fired autocomplete. You can use this.element.attr("id") or some other method to modify the JSONP url.

Demo here and code here

Sign up to request clarification or add additional context in comments.

1 Comment

It works! After hours of banging my head against the wall! Amazing Demo, thank for the tip!

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.