JQuery Search Text and UI functionality

I was able to create a search box but as the user types, I wanted the user the ability to narrow down their search.  So let's say that when the user starts typing, there are 100 records to be displayed, if a user types 3 or 4 letters to narrow down their search, I want only the filtered text to appear so maybe there would only be 10 or so records.  Below is my code on pulling all of the records but as I type, the list doesn't change nor does it narrow down.  How would I do this?  Please view code below:

<!DOCTYPE html>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
    <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
    <meta charset="utf-8" />   
<div class="ui-widget">
        <input type="text" id="search" name="search" />
 <script type="text/javascript">
         source: function (request, response) {
                 url: "",
                 dataType: "json",
                 data: { term: request.term },
                 success: function (data) {
                     response($.map(data, function (item) {
                         return {
                             label: item.deptName,
                             id: item.deptId
         minLength: 3,
         select: function (event, ui) {


Open in new window

Who is Participating?

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

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.

<!DOCTYPE html>
    @*credit to http://kilianvalkhof.com/2010/javascript/how-to-build-a-fast-simple-list-filter-with-jquery/*@
    <title>Simple Map</title>
    <meta name="viewport" content="initial-scale=1.0">
    <meta charset="utf-8">
    <script src="~/Scripts/jquery-1.9.1.min.js"></script>
    <script type="text/javascript">
        (function ($) {
            // custom css expression for a case-insensitive contains()
            jQuery.expr[':'].Contains = function (a, i, m) {
                return (a.textContent || a.innerText || "").toUpperCase().indexOf(m[3].toUpperCase()) >= 0;

            function listFilter(header, list) { // header is any element, list is an unordered list
                // create and add the filter form to the header
                var form = $("<form>").attr({ "class": "filterform", "action": "#" }),
                    input = $("<input>").attr({ "class": "filterinput", "type": "text" });

                  .change(function () {
                      var filter = $(this).val();
                      if (filter) {
                          // this finds all links in a list that contain the input,
                          // and hide the ones not containing the input while showing the ones that do
                          $(list).find("a:not(:Contains(" + filter + "))").parent().slideUp();
                          $(list).find("a:Contains(" + filter + ")").parent().slideDown();
                      } else {
                      return false;
                .keyup(function () {
                    // fire the above change event after every letter

            $(function () {
                listFilter($("#header"), $("#list"));
        body {
            background: #fff; 

        #wrap {
            position: relative;
            width: 220px;
            margin: 50px auto 0;

        #header {
            position: relative;
            line-height: 1em;

        .filterform {
            width: 220px;
            font-size: 12px;
            display: block;

            .filterform input {
                -moz-border-radius: 5px;
                border-radius: 5px;
                -webkit-border-radius: 5px;
    <h1 id="header">List of countries</h1>

    <ul id="list">
        <li><a href="#/australia/">Australia</a></li>
        <li><a href="#/austria/">Austria</a></li>
        <li><a href="#/belgium/">Belgium</a></li>
        <li><a href="#/brazil/">Brazil</a></li>
        <li><a href="#/canada/">Canada</a></li>
        <li><a href="#/denmark/">Denmark</a></li>
        <li><a href="#/finland/">Finland</a></li>
        <li><a href="#/france/">France</a></li>
        <li><a href="#/germany/">Germany</a></li>
        <li><a href="#/greece/">Greece</a></li>
        <li><a href="#/ireland/">Ireland</a></li>
        <li><a href="#/israel/">Israel</a></li>
        <li><a href="#/italy/">Italy</a></li>
        <li><a href="#/japan/">Japan</a></li>
        <li><a href="#/luxembourg/">Luxembourg</a></li>
        <li><a href="#/mexico/">Mexico</a></li>
        <li><a href="#/netherlands/">Netherlands</a></li>
        <li><a href="#/norway/">Norway</a></li>
        <li><a href="#/poland/">Poland</a></li>
        <li><a href="#/portugal/">Portugal</a></li>
        <li><a href="#/russia/">Russia</a></li>
        <li><a href="#/spain/">Spain</a></li>
        <li><a href="#/sweden/">Sweden</a></li>
        <li><a href="#/switzerland/">Switzerland</a></li>
        <li><a href="#/turkey/">Turkey</a></li>
        <li><a href="#/united-kingdom/">United Kingdom</a></li>
        <li><a href="#/united-states/">United States</a></li>

Open in new window

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
VBBRettAuthor Commented:
Thank you for the solution.
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

From novice to tech pro — start learning today.