7
I have a combobox connected to a textbox by a function. It works like this: while the person type something in the textbox, a kind of 'filter' is automatically performed in the combobox, which shows something that could correspond to what the person wants to inform (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 would like to know how to fill the textbox contents automatically with the filtered contents of the combobox when giving enter or tab. From now on, thank you.
Thank you very much!!!
– Juliana Bentes
Can you vote on my answer as a solution? rsrs thank you !
– Rafael Rotiroti