0
I’m working with a registration system, where all employees will be registered, but not all will have access to the program. For that, I’m using a select with the level of access he 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, they will need a user to log in. I am showing or hiding the user field using this function of Javascript:
<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 change from "Administration" to "No Access", for example, the field is still there. How do I check each time the option is changed?
I am using PHP and the part of login is ready, but would like when someone who is logged in to register a user, the "user" field appears and disappears as the option select "nivel_access" is changed. This is already happening, but only the first time. I would like it to happen every time the option is changed.
– Lucas Ramos