0

I am new to jquery and I was assigned to filter out the list once the item is already selected. There are 3 textboxes that uses the autocomplete.

source: apple, orange, mango

textbox 1 = apple textbox 2 = apple should be filtered out in the list. it should only display orange and mango.

I was able to filter the source but the list still display the item. But the source gets updated once I refresh the page. I have found this question, here's a link but in my case instead of adding, i wanted to filter it out.

Any help is appreciated.

Thanks! Zel

1
  • Might be worth posting what you have done so far? Commented Aug 13, 2012 at 6:26

2 Answers 2

1

What i would do... Pass the value of the first textbox back to the server (& vice versa for each auto complete)

You could try something like this.

JQuery

$('#auto2_id').autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: 'some_url/SomeAction',
                    dataType: "json",
                    data: {
                        term: request.term,
                        filter: $('#auto1_id').val()
                    },
                    success: function (data) {
                        //do something
                    }
                })
            }
        });

server side (not sure what language you're using. but in c# (rough code sample))

public ActionResult SomeAction(string term, string filter)
{
  var data = _repo.GetAllCached().Where(o => o.Text != filter && o.Text.Contains(term));
  return Json(data , JsonRequestBehavior.AllowGet);
}
Sign up to request clarification or add additional context in comments.

Comments

0

On each textbox changed event, you will have to remove that item from the list and recall the function (from the plugin). You must have been calling all of the three functions at once.

Comments

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.