I have this select, where the user should select it:
<select asp-for="Configuracao.TipoEquipamento" class="form-control">
<option value="0">Catraca</option>
<option value="1">Fechadura</option>
</select>
But if it selects ratchet, the other select has gotten me filled in like this:
<select asp-for="Configuracao.SentidoTeclado" id="cbSentidoTeclado" class="form-control">
<option value="I">Irrelevante</option>
<option value="E">Entrada</option>
<option value="S">Saída</option>
</select>
Otherwise it has to be filled in as the following fields:
<select asp-for="Configuracao.SentidoTeclado" id="cbSentidoTeclado" class="form-control">
<option value="P">Principal</option>
<option value="S">Secundária</option>
<option value="D">Todos</option>
</select>
How can I change this at runtime via ajax? There will be several selects that will have to be changed.
I'm trying to do it this way: however every time I click on the cbTypeEquipment, it adds the data again:
$("#cbTipoEquipamento").change(function () {
//Pega o value da opção selecionada
let selectedValue = $("#cbTipoEquipamento option:selected").val();
//Depois disso, você pode fazer checar o valor do seu select e popular o outro select com as opções que você deseja.
if (selectedValue === '0') {
$("#cbSentidoTeclado").append($("<option />").val('I').text('Irrelevante'));
$("#cbSentidoTeclado").append($("<option />").val('E').text('Entrada'));
$("#cbSentidoTeclado").append($("<option />").val('S').text('Saída'));
} else {
$("#cbSentidoTeclado").append($("<option />").val('P').text('Principal'));
$("#cbSentidoTeclado").append($("<option />").val('S').text('Secundária'));
$("#cbSentidoTeclado").append($("<option />").val('D').text('Todos'));
}
});