1
I have three arrays, cities, capitals and population. How can I click on a given state to show in the inputs the respective values, i.e., capital and population of the selected state.
var cidades = new Array("Acre", "Bahia", "Minas Gerais", "Pernambuco", "Rio de Janeiro", "São Paulo")
var capital = new Array("Rio Branco", "Salvador", "Belo Horizonte", "Recife", "Rio de Janeiro", "São Paulo")
var populacao = new Array("829.619", "15.344.447", "21.119.536", "9.473.266", "16.718.956", "45.094.866" )
function getData() {
var estado = document.getElementById("estados");
document.getElementById("capital").value = ?????
document.getElementById("populacao").value = ????
}
getData();
Selecione o estado:
<select id="estados" onChange="getData(this.form)">
<option>Acre</option>
<option>Bahia</option>
<option>Minas Gerais</option>
<option>Pernambuco</option>
<option>Rio de Janeiro</option>
<option>São Paulo</option>
</select>
<br>
A capital é:
<input type="text" id="capital" size=13>
<br>
A população é:
<input type="text" id="populacao" size=6>