title: How to remove value from hidden field using jquery.autocomplete
body: <p>I have a page with two inputs: <code>users_list</code> and <code>users_ids</code>. jquery.autocomplete is used to autocomplete the <code>users_list</code>. <code>users_ids</code> is hidden field. When the user is selected and added to the <code>users_list</code> his id is added to the <code>users_ids</code>. Everything works fine. But the question is how to remove the value from <code>user_ids</code> if the user is removed from <code>users_list</code>?</p>
  
  <p>The script:</p>
  
  <pre><code>$(document).ready(function(){
      function formatItem(row) {
        return row[0] + " (&lt;strong&gt;id: " + row[1] + "&lt;/strong&gt;)";
      }
      function formatResult(row) {
        return row[0].replace(/(&lt;.+?&gt;)/gi, '');
      }
      $("#users_list").autocomplete("&lt;%= url_for(:controller =&gt; :users,
                                                 :action =&gt; :autocomplete_users_list) %&gt;",
      {
        multiple: true,
        matchContains: true,
        mustMatch: true,
        autoFill: true,
        formatItem: formatItem,
        formatResult: formatResult
      });
  
      $("#users_list").result(function(event, data, formatted) {
        var hidden =  $("#users_ids");
          hidden.val( (hidden.val() ? hidden.val() + ";" : hidden.val()) + data[1]);
      });
    });
  </code></pre>