Combo Select does not work

0

I need the second <select> to receive the data according to the choice of the first one. The <option> appears in the first <select> , but in the second it does not move.

I have a textdata folder with all .txt for <option> of each match.

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><scriptsrc="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 .txt files

<option>São Paulo - SP001</option>
<option>Adamantina - SP002</option>
<option>Adolfo - SP003</option>
<option>Aguaí - SP004</option>
<option>Águas da Prata - SP005</option>
    
asked by anonymous 06.11.2018 / 18:16

1 answer

1

Hello, at first your code is correct. What is happening is that your .txt files are not inside an HTTP server and so jQuery does not load them. Please install the Web Server in Chrome and configures it to serve the files in your folders. My folder structure looks like this:

C:\stackoverflow\exemplo01
C:\stackoverflow\exemplo01\index.html
C:\stackoverflow\exemplo01\textdata\AC.txt

I configured the Web Server to serve the files in the * C: \ stackoverflow * folder.

Then you only have to access your folder in the browser using the Web Server URL:

http://127.0.0.1:8887/exemplo01/

Your code is correct:

    
06.11.2018 / 18:52