Let's say I have the following SELECT
in my HTML:
<form name="formularioEstados">
<label for="states">Selecione um estado:<br>
<select id="states" name="estados" onChange="mostraCapital()">
<option value=""></option>
<option value="AC">Acre</option>
<option value="AL">Alagoas</option>
<option value="AP">Amapá</option>
<option value="AM">Amazonas</option>
<option value="BA">Bahia</option>
<option value="CE">Ceará</option>
<option value="DF">Distrito Federal</option>
<option value="ES">Espirito Santo</option>
<option value="GO">Goiás</option>
<option value="MA">Maranhão</option>
<option value="MS">Mato Grosso do Sul</option>
<option value="MT">Mato Grosso</option>
<option value="MG">Minas Gerais</option>
<option value="PA">Pará</option>
<option value="PB">Paraíba</option>
<option value="PR">Paraná</option>
<option value="PE">Pernambuco</option>
<option value="PI">Piauí</option>
<option value="RJ">Rio de Janeiro</option>
<option value="RN">Rio Grande do Norte</option>
<option value="RS">Rio Grande do Sul</option>
<option value="RO">Rondônia</option>
<option value="RR">Roraima</option>
<option value="SC">Santa Catarina</option>
<option value="SP">São Paulo</option>
<option value="SE">Sergipe</option>
<option value="TO">Tocantins</option>
</select>
</label>
<br>
<label for="capital"> A sua capital é: <br>
<input id="capital" type="text" name="nomeCapital" disabled>
</label>
</form>
To get the value of the selected state we use the onChange
event, and the teacher of my technical course taught us as follows:
var estado = document.formularioEstados.estados.value;
Is this the best way to do it, is it right, or is there a more efficient and correct way?