title: CodeIgniter/JQuery/Ajax: Set dropdown based on previously selected value
body: <p>I know this has been asked in various ways, but I have not been able to find a clear answer to my problem.  I'm using a combo if CI/JQuery/Ajax for CRUD operations within my app.  Within my create are multiple dropdowns, which are populated from the database...the ID of each user selection is stored with the new record upon saving.  When a user updates that record, I need to be able to render the update page, with the dropdowns populated, but set to the selected value.  Any guidance you can provide on where in the app/how I can set this is greatly appreciated.  Below are snippets of the code I am using:</p>
  
  <p>JQuery:</p>
  
  <pre><code>$.ajax({
  url: 'index.php/admin/getEventById/' + updateId,
  dataType: 'json',            
  success: function( response ) {
  $( '#uEventName' ).val( response.event_name );
  $( '#uEventType' ).val( response.eventType_eventType_id ); /*Obviously, this would work fine if I was setting the value of a textbox but this is the ID# of the value I want to have my dropdown default to */
  </code></pre>
  
  <p>My View:</p>
  
  <pre><code> &lt;p&gt;
      &lt;label for="uEventName"&gt;Event Name:&lt;/label&gt;
       &lt;input type="text" id="uEventName" name="uEventName" /&gt;
    &lt;/p&gt;
    &lt;p&gt;
       &lt;label for="uEventType"&gt;Event Type:&lt;/label&gt;   &lt;!--I'm populating the dropdown with all values, but need it to be set to value as obtained above (via the response) --&gt;
              &lt;?php        
                  $eventtype_options = array();
                  foreach($eventtypes as $eventtype){
                  $eventtype_options[$eventtype-&gt;eventtype_id]=$eventtype-&gt;event_type;
                  }
                  echo "&lt;td&gt;" . form_dropdown('uEventType', $eventtype_options) . "&lt;/td&gt;";
              ?&gt;         
              &lt;/p&gt;  
  </code></pre>