I have a combobox connected to a textbox by a function. It works like this: while the person types something in the textbox, a kind of 'filter' is automatically performed in the combobox, which shows something that could match what the person wants to report (in this case, a city).
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script language="javascript">
function trocaOpcao(valor, objSel) {
for (i=0; i < objSel.length; i++){
qtd = valor.length;
if (objSel.options[i].text.substring(0, qtd).toUpperCase() == valor.toUpperCase()) {
objSel.selectedIndex = i;
break;
}
}
}
</script>
<style>
/*removendo o estilo do select*/
select {
-webkit-appearance: none;
-moz-appearance: none;
text-indent: 1px;
text-overflow: '';
border: none;
}
</style>
</head>
<body>
<form name="form">
<input type="text" name="texto" onkeyup="trocaOpcao(this.value, document.form.cidade);"></br>
<select disabled name="cidade">
<option selected>Sua Cidade</option>
<option>sao paulo</option>
<option>rio de janeiro</option>
<option>vitoria</option>
<option>belem</option>
<option>recife</option>
<option>santa luzia</option>
<option>santa cruz</option>
<option>santarem</option>
</select>
</form>
</body>
</html>
I'd like to know how to populate the contents of the textbox automatically with the filtered contents of the combobox by giving 'enter' or 'tab'. Thanks in advance.