1
I have two inputs
of the kind date
. One for the user to enter the start date and the other to enter a final date. I created a variable that receives the current date using only the new Date
.
I have a function that checks whether the current date is longer than the final date. If yes, it returns a message. If not, it returns a different message. I tested on two browsers, Firefox and Chrome. In Firefox this function correctly returns the validations. The problem comes now, in Chrome it does not understand the conditions of if
and else
that I created.
window.onload = function () {
var d1 = document.getElementById('inicio').valueAsDate
var d2 = document.getElementById('fim').valueAsDate
var agora = new Date()
console.log(agora)
var btn = document.getElementById('btn')
btn.addEventListener('click', function checkTime() {
if(agora > d2) {
console.log('Turma finalizada.')
} else
console.log('Turma em andamento.')
})
}
<input type="date" id="inicio">
<input type="date" id="fim">
<input type="button" value="Clique" id="btn">
Thank you so much, really. You saved me for today. It’s working perfectly in Chrome too. I’m a beginner in Js and need to study more. I’m glad there’s a stackoverflow :-)
– M. Bran