title: Dynamic search results on keystroke
body: <p>I have a list of items stored in a database.</p>
  
  <p>I am using a foreach to list the items returned with a checkbox next to each item like so:</p>
  
  <pre><code>            var db = Database.Open("database");
              var sql = "SELECT * from table";
              var result = db.Query(sql);
  </code></pre>
  
  <p>...</p>
  
  <pre><code>@{foreach (var user in result) {
              &lt;tr&gt;&lt;td&gt;@table.attribute&lt;/td&gt; &lt;td&gt;@table.secondAttribute @table.thirdAttribute&lt;/td&gt;
                  &lt;td&gt;&lt;input type="checkbox" name="attribute" value="attribute" /&gt;&lt;/td&gt;&lt;/tr&gt;
  </code></pre>
  
  <p>The functionality I would like to have is a textbox which, upon the user typing a letter, would limit the number of items listed by my foreach based on what character the user enters. So I've tried to use the JQuery autoComplete module, but I'm not entirely sure how to use it in this case, or even if it is possible.</p>
  
  <p>So I added in :</p>
  
  <pre><code> $(function(){
              $('#name').autocomplete({source:'getUsers'});
          });
  </code></pre>
  
  <p>...
      Enter their name: 
                    </p>
  
  <p>And then in getUsers : </p>
  
  <pre><code>@{
      var db = Database.Open("database");
      var term = Request.QueryString["term"] + "%";
      var sql = "SELECT * from table where attribute LIKE @0 OR secondAttribute LIKE @0 OR thirdAttribute LIKE @0";
     var result = db.Query(sql, term);
      var data = result.Select(p =&gt; new{label = p.attribute + " " + p.secondAttribute});
      Json.Write(data, Response.Output);
  }
  </code></pre>
  
  <p>This, of course, just retrieves the data for the textbox and doesn't delimit the returned checkboxes at all. Is there a way I can do this ?</p>