0
I got two camps like date
in my form, the field data_inicio
and data_fim
.
I need to ride a script
that when I finish filling out the dates, that is when the fields lose focus, an alert is issued warning if data_inicio
is larger than the data_fim
, whereas the data_inicio
never may be greater than the data_fim
.
I already made a script using the event onclik
, but it only warns when I click on submit
.
Follow the code below:
function comparadatas()
{
var data_inicio = document.getElementById("data_inicio").value;
var data_fim = document.getElementById("data_fim").value;
if(data_inicio > data_fim){
alert("ERRO! A DATA DE NOTICAÇÃO NAO PODE SER MAIOR DO QUE A DATA DE COMPARECIMENTO");
}
}
<form>
<label for="data_inicio">Data Inicio</label>
<input type="date" name="data_inicio" id="data_inicio"><br/>
<label for="data_fim">Data Final</label>
<input type="date" name="data_fim" id="data_fim"><br/>
<input type="submit" value="REALIZAR CADASTRO" onclick="comparadatas()">
</form>
Good morning guys, thank you so much for your help, I managed to solve
– odmarques
Missed to mark the other as correct. '-'
– Valdeir Psr