How to select the result of a json CEP in an existing option?

0
$.getJSON(url, function(json){

    $("#pf_endereco").val(json.logradouro);
    $("#pf_bairro").val(json.bairro);
    $("#cidade").val(json.localidade); <----
    $("#estado").val(json.uf); <----

How to put locality and uf information as shown by these arrows ( <---- ) within a form when it is of type select > option ? >

  

Update

json.localidade - "MS"
json.localidade - "Campo Grande"

<option value=""></option>
<option value="000001">AC</option>
<option value="000002">AL</option>
<option value="000003">AM</option>
<option value="000004">AP</option>
  

Update 2

    
asked by anonymous 22.10.2014 / 03:21

1 answer

2

If you can not change what comes in JSON to hit with your% s of% s, you need a selector that looks at the contents of the options, not their value:

$("#estado option:contains('" + json.uf + "')").prop('selected', true);
$("#cidade option:contains('" + json.localidade + "')").prop('selected', true);
    
22.10.2014 / 03:56