How to select an option of a combobox from ajax that has different option values?
(Note: although I mentioned Magento, this is NOT a Magento question, it's about jquery).
I have a form and I've used a jquery script to autocomplete address based on zip code. The problem is that Magento brings a state/region list which values are different than I got from ajax result (webservice). For example: the value returned for state is "SP" (Sao Paulo) and the value that should match in select is "508" instead of "SP". How to populate that select correctly?
See the select here (Magento generates it dinamically, from db):
- <select id="region_id" name="region_id" title="Estado" class="validate-select required-entry" defaultvalue="">
- <option value="">Selecione o Estado...</option>
- <option value="485">Acre</option>
- <option value="486">Alagoas</option>
- <option value="487">Amapá</option>
- <option value="488">Amazonas</option>
- <option value="489">Bahia</option>
- <option value="490">Ceará</option>
- <option value="511">Distrito Federal</option>
- <option value="491">Espírito Santo</option>
- <option value="492">Goiás</option>
- <option value="493">Maranhão</option>
- <option value="495">Mato Grosso do Sul</option>
- <option value="494">Mato Grosso</option>
- <option value="496">Minas Gerais</option>
- <option value="499">Paraná</option>
- <option value="498">Paraíba</option>
- <option value="497">Pará</option>
- <option value="500">Pernambuco</option>
- <option value="501">Piauí</option>
- <option value="503">Rio Grande do Norte</option>
- <option value="504">Rio Grande do Sul</option>
- <option value="502">Rio de Janeiro</option>
- <option value="505">Rondônia</option>
- <option value="506">Roraima</option>
- <option value="507">Santa Catarina</option>
- <option value="509">Sergipe</option>
- <option value="508">São Paulo</option>
- <option value="510">Tocantins</option>
- </select>
I have no idea how to "associate" each option number with the possible results from ajax.
Any helps?