I'm working with a registration system, where all employees will be registered, but not everyone will have access to the program. For this, I'm using a select with the level of access it will have.
<div class="form-group">
<label for="nivel_acesso" class="col-sm-2 control-label">Nível de Acesso</label>
<div class="col-sm-2">
<select class="form-control" id="nivel_acesso" required onchange="option_check()">
<option value="">Selecione</option>
<option value="0">Sem Acesso</option>
<option value="1">Administração</option>
<option value="2">Informática</option>
</select>
</div>
</div>
<div class="form-group" id="hidden_div" style="display:none;">
<label for="usuario" class="col-sm-2 control-label">Usuário</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="usuario" placeholder="Usuário" required>
</div>
</div>
For example, if I want to register an employee who will have access to the administration part, he will need a user to log in. I am showing or hiding the user field using this JavaScript function:
<script type="text/javascript">
function option_check(){
if(document.getElementById("nivel_acesso").value != "0" && document.getElementById("nivel_acesso").value != ""){
document.getElementById("hidden_div").style.display = "block";
}
}
And it works the first time, however, if I switch from "Administration" to "No Access", for example, the field is still there. How do I check each time the option is changed?