1
Hello! I am not able to compare the dates of a user input with today’s date. To be able to return an alert to the user. I made another example and it worked, but this one didn’t. Can anyone see the error(s) (s)?
<script type="text/javascript">
function validarData(){
var data_entrega = document.getElementById('data_entrega').value;
var data = new Date(); //obtem data hoje
var dia = data.getDate(); // 1-31
var mes = data.getMonth(); // 0-11 (zero=janeiro)
var ano4 = data.getFullYear(); // 4 dígitos
var data_hoje = dia + '/' + (mes+1) + '/' + ano4; //formatação igual ao input do usuário
var sete_dias = data_hoje + 7; // regra 7 dias (chroma)
if(data_entrega < data_hoje){
alert("Atenção! Data de entrega já passou!");
}else if(data_entrega > sete_dias){
alert("Atenção! Data de entrega ultrapassa 7 dias!");
}
}
</script>
<input type="date" name="data_entrega" id="data_entrega" class="form-control" value="" required="" onblur="validarData()">
Thank you!
Thank you for answering. So, I’m bringing for the Onblur event in input, I take the value of it ( var data_delivery = Document.getElementById('data_delivery').value;). You have to do something else?
– Isadora Almeida
I got it solved! Thanks anyway! Had to format the user date.
– Isadora Almeida