How to make a "Select" in html receive the value of a texbox and display the option according to what is typed in the textbox?
My code so far:
<html>
<head>
<script type="text/javascript">
function teste(){
var e = document.getElementById("EmpNomeIni");
var itemSelecionado = e.options[e.selectedIndex].value;
var txtEmpIni = document.getElementById("EmpIni");
if(itemSelecionado == 1)
{
txtEmpIni.value = "01";
}
else if(itemSelecionado == 2)
{
txtEmpIni.value = "02";
}
else if(itemSelecionado == 3)
{
txtEmpIni.value = "03";
}
}
function MudaValDDLComTXT(){
var e = document.getElementById("EmpNomeIni");
var itemSelecionado;
var txtEmpIni = document.getElementById("EmpIni");
if(txtEmpIni.value == "01")
{
itemSelecionado = 2;
e.options[e.selectedIndex].value = itemSelecionado;
}
}
</script>
</head>
<body>
<div id="dados">
<label for="EmpIni">Empresa Inicial: <br>
<input type="text" id="EmpIni" name="EmpIni" onKeyPress="" class="" onmouseover="" onmouseout="" title="Código da Empresa" maxlength="02" onblur="MudaValDDLComTXT();" value="">
</label>
<br>
<label for="CodTranspIni">Desc. Empresa Inicial:<br>
<select name="EmpNomeIni" id="EmpNomeIni" style="width:110px;" class="" onchange="teste();">
<option value="1">Empresa 1</option>
<option value="2">Empresa 2</option>
<option value="3">Empresa 3</option>
</select>
</label>
<br>
</div>
</body>
</html>