Combobox with DropDown in SharePoint 2010 to Filter Lists

Hello,

I am trying to create a combobox list filter (with a dropdown) that will filter a list that is on the page, and I am not sure what is going wrong. When I run the debugger I get an error the listUrl is undefined. I tried to add a listUrl by saying var listUrl = url + ?filter, etc and nothing worked. Here is my complete code. I am trying to use the alert to at least validate I have something coming from the listUrl.

<link href="/Style%20Library/SPLibraries/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="/Style%20Library/js/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="/Style%20Library/SPLibraries/jquery-ui.min.js" type="text/javascript">


    <script src="https://mysite.edu/Style%20Library/SPLibraries/jquery.SPServices-2014.02.js" type="text/javascript"></script>
<script language="ecmascript" type="text/ecmascript">

    // Settings
    var url = "https://mysite/_vti_bin/listdata.svc/Degreecodes()";
    var field = "Title";

    // Onload
    $(document).ready(function () {
        $("#tags").autocomplete({
            source: function (req, add) {
                var suggestions = search(req.term, url, field);
                add(suggestions);

            }
        });
    });

    // Search all the listitems by using the REST Service
    // Value is the text that needs to be used in the query
    // listurl is the listdata.svc url withouth the filter params
    // field is the name of the field where the value in exists

    function search(value, listUrl, field) {
        var coll = new Array();
        var url = listUrl + "?$filter=substringof('" + value + "'," + field + ")";
      
        $.ajax({
            cache: true,
            type: "GET",
            async: false,
            dataType: "json",
            url: url,
            success: function (data) {
                var results = data.d.results;
                for (att in results) {
                    var object = results[att];
                    for (attt in object) {
                        if (attt == field) {
                            coll.push(object[attt]);
                        }
                    }
                }
            }
        });
        return coll;
    }</script>

<div class="demo" style="width: 200px"><div class="ui-widget"><label for="tags">Search: </label><input class="ui-autocomplete-input" id="tags"  autocomplete="off"  /> </div></div>
<div class="ms-error" id="error">&#160;<input id="byBtn" onclick="alert(listurl);" type="submit" value="Submit Query" /></div>

Open in new window

mSproutAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

colly92002Commented:
IS it line 31 that throws the error?  Can you check line 17, I would guess that req.term is null since url and field are both set locally.
0
mSproutAuthor Commented:
https://select2.github.io/

$(".js-data-example-ajax").select2({
  ajax: {
    url: "https://api.github.com/search/repositories",
    dataType: 'json',
    delay: 250,
    data: function (params) {
      return {
        q: params.term, // search term
        page: params.page
      };
    },
    processResults: function (data, page) {
      // parse the results into the format expected by Select2.
      // since we are using custom formatting functions we do not need to
      // alter the remote JSON data
      return {
        results: data.items
      };
    },
    cache: true
  },
  escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
  minimumInputLength: 1,
  templateResult: formatRepo, // omitted for brevity, see the source of this page
  templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mSproutAuthor Commented:
Using Ajax and the right Jquery plugin I was able to find the solution.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SharePoint

From novice to tech pro — start learning today.