1
I need to clear the filled values of 2 fields of the type select
when filling in a field of the type input
.
When filling in the field input
by name postcode
i want the values of the fields of type select
by name country_id
and zone_id
are cleaned so that it is necessary to select them again.
Just follow my code:
<div class="form-group required">
<input type="text" name="postcode" value="" placeholder="Coloque seu CEP" id="input-order-postcode" class="form-control" />
</div>
<div class="form-group required">
<select name="country_id" id="input-order-country" class="form-control country-selector" data-post-code-required="#input-order-postcode" data-zone="#input-order-zone">
<option value="" selected="selected"> --- Selecione o País --- </option>
<option value="30">Brasil</option>
</select>
</div>
<div class="form-group required">
<select name="zone_id" id="input-order-zone" class="form-control">
<option value="" data-sigla='' selected="selected"> --- Selecione o Estado --- </option>
<option value="440" data-sigla='AC'>Acre</option>
<option value="441" data-sigla='AL'>Alagoas</option>
<option value="442" data-sigla='AP'>Amapá</option>
<option value="443" data-sigla='AM'>Amazonas</option>
<option value="444" data-sigla='BA'>Bahia</option>
<option value="445" data-sigla='CE'>Ceará</option>
<option value="446" data-sigla='DF'>Distrito Federal</option>
<option value="447" data-sigla='ES'>Espírito Santo</option>
<option value="448" data-sigla='GO'>Goiás</option>
<option value="449" data-sigla='MA'>Maranhão</option>
<option value="450" data-sigla='MT'>Mato Grosso</option>
<option value="451" data-sigla='MS'>Mato Grosso do Sul</option>
<option value="452" data-sigla='MG'>Minas Gerais</option>
<option value="453" data-sigla='PA'>Pará</option>
<option value="454" data-sigla='PB'>Paraíba</option>
<option value="455" data-sigla='PR'>Paraná</option>
<option value="456" data-sigla='PE'>Pernambuco</option>
<option value="457" data-sigla='PI'>Piauí</option>
<option value="458" data-sigla='RJ'>Rio de Janeiro</option>
<option value="459" data-sigla='RN'>Rio Grande do Norte</option>
<option value="460" data-sigla='RS'>Rio Grande do Sul</option>
<option value="461" data-sigla='RO'>Rondônia</option>
<option value="462" data-sigla='RR'>Roraima</option>
<option value="463" data-sigla='SC'>Santa Catarina</option>
<option value="464" data-sigla='SP'>São Paulo</option>
<option value="465" data-sigla='SE'>Sergipe</option>
<option value="466" data-sigla='TO'>Tocantins</option>
</select>
</div>
You can specify only the 2
select
?– Wendell
@Wendell has it, you can use it
ID
and separate by commas like this:$('#input-order-zone, #input-order-country').val('');
– Sergio
Sergio, it worked. The only problem is that you need to click outside the
input
so that the fieldsselect
go back to the initial state. There would be some way this could be done without having to click outside the field?– Wendell
@Wendell yes, I left a comment on that in the reply. There are different events you can use, for example
$('input#input-order-postcode').on('change, input, keyup', function() {
. So he listens to 3 events, but if you don’t need them all take some.– Sergio
Wonderful! Just what you need, thank you.
– Wendell