title: JQuery: Select Option from DropDownList given value of adjacent cell in table
body: <p>I am creating a survey that is conducted each year.  To make it fast, i want to have a button that will automatically select the answer in a dropdownlist from the previous year's survey (this answer is available as a span in a preceding cell (same row) in a table). Because this table can be hundreds of rows, i can't use specific id/name selectors.  What i am trying to do is store the span located before the hyperlink in a variable, and then use that to select an option in the cell following the hyperlink</p>
  
  <p><strong>Jquery:</strong></p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
       $(function () {
           $("[id$='lbCopy']").click(
              function () {
                  var $prevReason = $(this).parent().prev().children().text();
                  $(this).parent().next().children('select &gt; option:contains("' + $prevReason + '")').prop("selected", true); 
              })
       });
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>HTML:</strong></p>
  
  <pre><code>&lt;td&gt;
      &lt;span id="ctl00_body_gvBacklog_ctl02_lblPrevYearReason"&gt;Recalcitrant RP&lt;/span&gt;
  &lt;/td&gt;
  &lt;td&gt;
      &lt;a id="ctl00_body_gvBacklog_ctl02_lbCopy"&gt;Copy&lt;/a&gt;
  &lt;/td&gt;
  &lt;td&gt;
      &lt;select name="ctl00$body$gvBacklog$ctl02$ddlReasonNotClosed" id="ctl00_body_gvBacklog_ctl02_ddlReasonNotClosed"&gt;
          &lt;option value=""&gt;&lt;/option&gt;
          &lt;option value="Contamination Above Standards"&gt;Contamination Above Standards&lt;/option&gt;
          &lt;option value="Recalcitrant RP"&gt;Recalcitrant RP&lt;/option&gt;
          &lt;option value="Remediation Ongoing"&gt;Remediation Ongoing&lt;/option&gt;
          &lt;option value="SMAC Eligible"&gt;SMAC Eligible&lt;/option&gt;
          &lt;option value="SMAC Eligible w/MW Closure"&gt;SMAC Eligible w/MW Closure&lt;/option&gt;
          &lt;option value="SMAC Eligible w/Notice"&gt;SMAC Eligible w/Notice&lt;/option&gt;
      &lt;/select&gt;
  &lt;/td&gt;
  </code></pre>
  
  <p>For whatever reason this does not work. I get no errors, but the dropdownlist does not get modified. I know my selector is solid, because i can use it to change the option of all dropdowns, just not the adjacent dropdown.  Thanks for the help!</p>