title: How to select option from dropdown and execute onchange Jquery
body: <p>I'm probably doing this in the worst way but I'm trying to a) select a dropdown option based on received data from a social networking plugin and b) force an onchange event to make the successive dropmenus appear and populate.</p>
  
  <p>I'm working with country, state and city data.  Upon page load, the country dropdown auto populates with two selections: Mexico and United states.  When one is selected, the state dropdown auto populates and once a state is selected the city dropdown populates.</p>
  
  <p>here's the markup:</p>
  
  <pre><code>&lt;tr&gt;
  &lt;td id="field-country" class="tags-form"&gt;&lt;/td&gt;
     &lt;td&gt;&lt;select onchange="CreateCountries.getRegions(this.value);"
  name="country_id" id="country_id" value="" style="width: 130px;"
  class="campos-tabla"&gt;&lt;/select&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
     &lt;td id="field-state" class="tags-form"&gt;&lt;/td&gt;
     &lt;td&gt;&lt;select onchange="CreateCountries.getCities(this.value);"
  name="state_id" id="state_id" value="" style="width: 130px;"
  class="campos-tabla"&gt;&lt;/select&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
     &lt;td id="field-city" class="tags-form"&gt;&lt;/td&gt;
     &lt;td&gt;&lt;select name='city_id' id="city_id" value=""class="campos-tabla"
  style="width: 130px;"&gt;&lt;/select&gt;&lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>and here's my attempt to a) select dropdown option based on data received and b) activate the onchange event so that the next dropdown menu will populate and then continue with my next selection:</p>
  
  <pre><code>_fillFields: function(){
   logingygia.fields.firstname.val(logingygia.firstname);
   logingygia.fields.lastname.val(logingygia.lastname);
   logingygia.fields.email.val(logingygia.email);
    if (logingygia.gender == 'm') {
      $('#genderM').attr('checked',true);
          }
          else {
              $('#genderF').attr('checked',true);
          };
   logingygia.fields.birthmonth.val(d2(logingygia.birthmonth));
   logingygia.fields.birthday.val(d2(logingygia.birthday));
   logingygia.fields.birthyear.val(logingygia.birthyear)
  if (logingygia.country == 'United States') {
          $('#country_id').val(212);
              }
              else {
                  $('#country_id').val(143);
              };
              if $('#country_id option: selected ').length){
  
                  if ($('#country_id option:selected').length)
                      $('#country_id').val("state_id).change();
                                  }else{
                                    return ("");
              };
              }
  };
  </code></pre>
  
  <p>The if (logingygia.country by itself will select the country correctly. Unfortunately, when I combine that with the "if country_id: option", no country is selected and the state dropdown will show up with only "Selecciona" but does not populate with any choices ... which makes sense since country was not selected.</p>
  
  <p>I'm sure the code is a mess so I would greatly appreciate some better minds to help me.</p>