Select Mandatory to select a different value

Asked

Viewed 31 times

-2

I have four input type="time" on my page and in front of them a select. By my default select comes disabled. I made a script that enables mine select only if at least one of the four input type="time" is completed. The first item of my select is "SELECIONAR JUSTIFICATIVA" and other items are loaded with items from a table in my database.

What I would like is this, there is the possibility that if at least one of the four input type="time" is completed by enabling the select, be required to select a value in this select different from the first value, that is, a value different from the "SELECIONAR JUSTIFICATIVA".

Is there such a possibility?

Below is an example code with the four <input type="time"> and the select:

<input type="time" id="hora001" name="hora001" onchange="HabilitaSelectJust()">
<br>
<input type="time" id="hora002" name="hora002" onchange="HabilitaSelectJust()">
<br>
<input type="time" id="hora003" name="hora003" onchange="HabilitaSelectJust()">
<br>
<input type="time" id="hora004" name="hora004" onchange="HabilitaSelectJust()">
<br>
<br>
<select name="justificativa0" id="justificativa0" disabled>
<option>JUSTIFICAR MARCAÇÃO</option>
<option value="11">Abonado </option>
<option value="65">Admissao </option>
<option value="21">Atestado </option>
<option value="6">Compensação </option>
<option value="13">Crachá com Defeito </option>
<option value="57">Escola </option>
<option value="8">Esqueceu Cartão/Crachá </option>
<option value="61">Esqueceu de Registrar Ponto </option>
<option value="75">Falta de Energia Eletrica </option>
<option value="81">Home Office </option>
<option value="72">Horario de Verão </option>
<option value="43">Integração </option>
<option value="63">Marcação Inválida </option>
<option value="2">Não passou Cartão/Cracha </option>
<option value="1">Não passou Digital </option>
<option value="15">Não Possui Cartão Crachá </option>
<option value="14">Perdeu Crachá </option>
<option value="23">Problema com Cartão </option>
<option value="3">Relogio com Defeito </option>
<option value="26">Sem Internet </option>
<option value="7">Serviços Externos </option>
<option value="64">Trabalho Externo </option>
<option value="5">Treinamento </option>
<option value="70">Troca de Relogio </option>
<option value="68">Troca de Turno </option>
<option value="10">Viagem a Serviço </option>
</select>

And now, follow my javascript that enables the field select if at least one of the four <input type="time"> is completed:

<script>
function HabilitaSelectJust() {
        if(document.getElementById("hora001").value == ""
        && document.getElementById("hora002").value == ""
        && document.getElementById("hora003").value == ""
        && document.getElementById("hora004").value == "") {
        document.getElementById("justificativa0").setAttribute("disabled","disabled");
    } else {
        document.getElementById("justificativa0").removeAttribute("disabled");
    }
}
</script>

1 answer

-3

below the line

document.getElementById("justificativa0").removeAttribute("disabled");

add

document.getElementById("justificativa0").setAttribute("required",1");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.