I have a field to select two other fields. When it shows the field situation hides the other div and vice versa, this is working perfectly. I would like to know how I can do to give an autofocus required when the selected field is visible, because, I already tried to put the command direct in the div and it happens that with this I disable the search button because, as the two fields are requesting something written ends not working. Here's my code.
<!--Script que esconde e mostra Divs-->
<script type="text/javascript">
window.onload = function(){
id('tipo').onchange = function(){
if( this.value=="" || this.value=="contrato" || this.value=="cliente" || this.value=="cpf" || this.value=="numero" || this.value=="solicitante" )
id('filtro').style.display = 'block';
else
id('filtro').style.display = 'none';
if( this.value=="situacao" )
id('seletor').style.display = 'block';
else
id('seletor').style.display = 'none';
}
}
function id(el){
return document.getElementById(el);
}
</script>
<!--Fim Script que esconde e mostra Divs-->
<!--Campo Tipo-->
<form method="get" action="pesquisas.php">
<div class="row">
<div class="col-sm-5">
<div class="input-group col-lg-12">
<div class="input-group-addon">
<span class="glyphicon glyphicon-search"></span>
</div>
<select required autofocus class="form-control" name="tipo" id="tipo">
<option value="">SELECIONAR</option>
<option value="situacao">SITUAÇÃO</option>
<option value="contrato">CONTRATO</option>
<option value="cliente">CLIENTE</option>
<option value="cpf">CPF</option>
<option value="numero">NÚMERO</option>
<option value="solicitante">SOLICITANTE</option>
</select></form></div></div>
<!--Fim Campo Tipo-->
<!--Campo Situaçao-->
<div class="col-sm-2 col-lg-4" >
<select type="text" class="form-control" name="seletor" id="seletor" style="display: none">
<option value="">SELECIONAR</option>
<option value="solicitada">SOLICITADA</option>
<option value="portada">PORTADA</option>
<option value="cancelada">CANCELADA</option>
<option value="erro">ERRO</option>
</select>
</div>
<!--Fim Campo Situaçao-->
<!--Campo de pesquisa escrita-->
<div class="col-sm-2 col-lg-4" >
<input type="text" class="form-control" name="filtro" id="filtro"></div>
<!--Fim Campo de pesquisa escrita-->
<input type="submit" value="Pesquisar" class="btn btn-primary"><br><br>