i'm doing in worst way i'm trying a) select dropdown option based on received data social networking plugin , b) force onchange event make successive dropmenus appear , populate.
i'm working country, state , city data. upon page load, country dropdown auto populates 2 selections: mexico , united states. when 1 selected, state dropdown auto populates , once state selected city dropdown populates.
here's markup:
<tr> <td id="field-country" class="tags-form"></td> <td><select onchange="createcountries.getregions(this.value);" name="country_id" id="country_id" value="" style="width: 130px;" class="campos-tabla"></select></td> </tr> <tr> <td id="field-state" class="tags-form"></td> <td><select onchange="createcountries.getcities(this.value);" name="state_id" id="state_id" value="" style="width: 130px;" class="campos-tabla"></select></td> </tr> <tr> <td id="field-city" class="tags-form"></td> <td><select name='city_id' id="city_id" value=""class="campos-tabla" style="width: 130px;"></select></td> </tr>
and here's attempt a) select dropdown option based on data received , b) activate onchange event next dropdown menu populate , continue next selection:
_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 (""); }; } };
the if (logingygia.country select country correctly. unfortunately, when combine "if country_id: option", no country selected , state dropdown show "selecciona" not populate choices ... makes sense since country not selected.
i'm sure code mess appreciate better minds me.
you're missing parenthese on 1 if, , i'm not sure if can have space after :. also, you're missing quote. , have same if twice.
if ($('#country_id option:selected').length){ $('#country_id').val('state_id').change(); }else{ return (""); };
fix syntax , see if fixes it.
Comments
Post a Comment