How can I mark a <select> option selected based on an inital value using jQuery?
<p>I have a screen with a  that has 50+ rows callect TopidID. On that screen I have a 
grid that can potentially have a large number of rows. As an alternative to every row
having a  with many choices I populate my selects with just the one item as below:</p>

<pre><code>&lt;td&gt; 
&lt;select title="X" data-clicked="N" data-list="N" id="input_TempRowKey_73" name="rowKey_73" class="select-topic"&gt;
   &lt;option value="0307"&gt;ABC&lt;/option&gt;
   &lt;/select&gt;
&lt;/td&gt;
</code></pre>

<p>When a user clicks on any of these row selects for the first time I then change the contents of the select and copy in the many options from the TopidID <code>&lt;select&gt;</code>. The code works and the action happens quickly so the user isn't aware that the new options are added.</p>

<pre><code> .on('click', '.select-topic', function () {
        if ($(this).attr('data-list') == "N") {
            $(this).attr('data-list', 'Y')
            var topicSelectHtml = $('#TopicID').clone().find("optgroup:first").remove().end().find("option[value$='**']").remove().end().html();
            $(this).html(topicSelectHtml);
            $(this).attr('data-clicked', 'Y')
        }
        return false;
    })
</code></pre>

<p>However I have a problem. When the user clicks then the new list appears and the original 
value that is selected (in this case ABC) is no longer selected. </p>

<p>Is there a way that I could do the following:</p>

<ol>
<li>Store away the original value in the select ( in this case 0307  and ABC )</li>
<li>Copy in the new choices to the new longer list of options and mark as "selected" the one in the list that matches what was there before ( in this case 0307 and ABC)</li>
</ol>

<p>Here is the format of the TopicID . It's very standard  code:</p>

<pre><code>&lt;select id="TopicID"&gt;
   &lt;optgroup label="Admin"&gt;
      &lt;option value="0000"&gt;All Topics&lt;/option&gt;
   &lt;/optgroup&gt;
   &lt;optgroup label="X"&gt;
      &lt;option value="0307"&gt;ABC&lt;/option&gt;
      &lt;option value="0308"&gt;DEF&lt;/option&gt;
   &lt;/optgroup&gt;
&lt;/select&gt;
</code></pre>
