0
I need the second <select>
receive the data according to the choice of the first. The <option>
in the first <select>
, but in the second it doesn’t move.
I have a folder textdata
with all .txt concerning the <option>
of each correspondence.
HTML
<select id="first-choice">
<option selected value="0">>>> Selecione</option>
<option value="AC">AC</option>
<option value="AL">AL</option>
<option value="AM">AM</option>
<option value="AP">AP</option>
<option value="BA">BA</option>
<option value="CE">CE</option>
<option value="DF">DF</option>
<option value="ES">ES</option>
<option value="GO">GO</option>
<option value="MA">MA</option>
<option value="MG">MG</option>
<option value="MS">MS</option>
<option value="MT">MT</option>
<option value="PA">PA</option>
<option value="PB">PB</option>
<option value="PE">PE</option>
<option value="PI">PI</option>
<option value="PR">PR</option>
<option value="RJ">RJ</option>
<option value="RN">RN</option>
<option value="RO">RO</option>
<option value="RR">RR</option>
<option value="RS">RS</option>
<option value="SC">SC</option>
<option value="SE">SE</option>
<option value="SP">SP</option>
<option value="TO">TO</option>
<option value="WW">WW</option>
</select>
<br>
<select id="second-choice">
<option>Selecionar UF</option>
</select>
JAVASCRIPT
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/JavaScript">
$("#first-choice").change(function() {
$("#second-choice").load("textdata/" + $(this).val() + ".txt");
});
</script>
A part of one of the archives .txt
<option>São Paulo - SP001</option>
<option>Adamantina - SP002</option>
<option>Adolfo - SP003</option>
<option>Aguaí - SP004</option>
<option>Águas da Prata - SP005</option>
Pq is loading 2 different jquerys at the same time?
– Sam
Try to place the second parameter of the
.load()
to give an Alert stating whether the shipment was successfully done or not, it helps a lot to discover.– Máttheus Spoo
The values of the 1st select are uppercase, so the names of . txt tb must be uppercase (e.g. AC.txt, SP.txt etc...) otherwise you will not find. Or you can convert to lower case values:
$(this).val().toLowerCase()
– Sam
@Sam doesn’t have a logical explanation for this. All txt are capitalized.
– César Mattos