Olá.
Estou fazendo um sistema para agendamento por horário. Tenho 2 select's: início e fim.
Preciso de uma função para impedir que o horário de fim, não possa ser menor que o de inicio + 3. Ex: inicio = 10, o fim deverá ser no mínimo 13, e não deixar selecionar 12 ou menor.
Abaixo o que tenho já:
<div>
<select id="inicio" onchange="horainicio()">
<option value="9">9:00</option>
<option value="10">10:00</option>
<option value="11">11:00</option>
<option value="12">12:00</option>
<option value="13">13:00</option>
<option value="14">14:00</option>
<select>
<select id="fim" onchange="horafim()">
<option value="12">12:00</option>
<option value="13">13:00</option>
<option value="14">14:00</option>
<option value="15">15:00</option>
<option value="16">16:00</option>
<option value="17">17:00</option>
<select>
Resultado:<br/>
<input type="text" id="resultado">
<button type="button" onclick="calcular()">Calcular</button>
</div>
<script>
function horainicio() {
var resultado = document.getElementById("resultado");
document.getElementById("fim").value = parseInt(inicio) + 3;
resultado.value = document.getElementById("fim").value-document.getElementById("inicio").value;
}
function horafim(){
resultado.value = document.getElementById("fim").value-document.getElementById("inicio").value;
}
</script>
Obrigado!