title: Converting a list into a select with jquery
body: <p>I'm trying to convert the following list into a select list so it can be submitted via a form - the  element within the lists will become the value of each option:</p>
  
  <pre><code>&lt;ul class="selected connected-list ui-sortable" style="height: 279px;"&gt;
  &lt;li class="ui-helper-hidden-accessible" style=""&gt;&lt;/li&gt;
  &lt;li title="Owner Name 1 - " class="ui-state-default ui-element ui-draggable" style="display: block; position: relative; top: 0px; left: 0px;"&gt;&lt;span class="ui-icon-arrowthick-2-n-s ui-icon"&gt;&lt;/span&gt;Owner Name 1 - &lt;em class="thenumber"&gt;4.4796E+11&lt;/em&gt;&lt;a class="action" href="#"&gt;&lt;span class="ui-corner-all ui-icon ui-icon-minus"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
  &lt;li title="David Moffat - " class="ui-state-default ui-element" style="display: block; position: relative; top: 0px; left: 0px;"&gt;&lt;span class="ui-icon ui-icon-arrowthick-2-n-s"&gt;&lt;/span&gt;David Moffat - &lt;em class="thenumber"&gt;07730423005&lt;/em&gt;&lt;a class="action" href="#"&gt;&lt;span class="ui-corner-all ui-icon ui-icon-minus"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>This should convert to the following format:</p>
  
  <pre><code>&lt;select style="display:none" class="selectoption" name="p_num[]" multiple="multiple"&gt;
  &lt;option value=""&gt;4.4796E+11&lt;/option&gt;
  &lt;option value=""&gt;07730423007&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>I have tried the following jquery code, but after many hours I'm pulling my hair out:</p>
  
  <pre><code>$('a.sendform').click(function(){
   $('ul.selected').each(function() {
    var $select = $('&lt;select /&gt;');
  
    $(this).find('li').each(function() {
     var $option = $('&lt;option /&gt;');
     $option.attr('value', $(this).('em')).html($(this).html());
     $select.append($option);
    });
    $(this).replaceWith($select);
   });
  });
  </code></pre>
  
  <p>Any help might save my remaining hair.</p>
  
  <p>Many thanks</p>
  
  <p>David</p>