0

In the following autocomplete script, how do I pass the results (value/label/description) to the select: option?

$( ".find_group_ac" ).autocomplete({
    minLength: 1,
    source: function(request, response) {
        $.ajax({
            url: "welcome/search/",
            data: { term: $(".find_group_ac").val()},
            dataType: "json",
            type: "POST",
            success: function(data) { 
                response($.map(data, function(obj) {
                    return {
                        label: obj.name,
                        value: obj.name,
                        description: obj.description 
                    };
                }));
            }
        });
    },
    select: function (ui, item) {
        alert (item.value);
    } 

})

1 Answer 1

2

The select handler is passed event and ui. ui.item refers to the selected item. With that in mind all you should need is:

select: function (event, ui) {
    alert (ui.item.label);
    alert (ui.item.value);
    alert (ui.item.description);
} 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, worked. I swear thats what I had first! Oh well, thanks again!

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.