title: Using jQuery .live to populate a dropdown and selecting an item
body: <p>See <a href="https://stackoverflow.com/questions/4381848/adding-jquery-drop-downs-to-a-variable-length-data-entry-page">here</a> if you want to see what I am doing.</p>
  
  <p>I can get a dropdrop list to load from a JSON source, but when I select an item the list reloads again. I know what the problem is, I just don't know the solution.</p>
  
  <pre><code>$("#RequestType").live("click", function() {
      var items = "&lt;option selected&gt;(Select)&lt;/option&gt;";
      $.each(jsonRequestType, function(i, item) {
          items += "&lt;option value='" + item.Id + "'&gt;" + item.Title + "&lt;/option&gt;";
      });
      $("#RequestType").html(items);
  });
  </code></pre>
  
  <p>I know the problem is "click", but I don't know what I should use instead.</p>
  
  <p><em>Update new related problem</em> The only problem I have now is when the edit page loads, I have to reselect my data in each drop down. How do I get the drop down to load when I load the page?</p>
  
  <p><strong>Working Code thus far minus problem above</strong></p>
  
  <p>The display</p>
  
  <pre><code>&lt;td&gt;&lt;%= Html.Hidden("RequestType", Model.DayRequested.RequestType, new { Class = "RequestTypeValue" })%&gt;
      &lt;%= Html.DropDownList("RequestTypeDdl", new List&lt;SelectListItem&gt; { new SelectListItem { Text = "(Select)", Value = "" } }, new { Class = "RequestTypeDdl" })%&gt;&lt;/td&gt;
  </code></pre>
  
  <p>And the script</p>
  
  <pre><code>// Get the request types for the drop down
  $(".RequestTypeDdl").live("focus", function() {
      var items = "&lt;option&gt;(Select)&lt;/option&gt;";
      var field = $(this);
      $.each(jsonRequestType, function(i, item) {
          items += "&lt;option value='" + item.Id + "'";
              if ($(field).prev("input").val() == item.Id)
                  items += " selected";
              items += "&gt;" + item.Title + "&lt;/option&gt;";
          };
      });
      $(this).html(items);
  });
  
  $(".RequestTypeDdl").live("change", function() {
      $(this).prev("input").val($(this).val());
  });
  </code></pre>