I have this code that I want to check if a date is in the past. I want to check it as soon as the date is entered, before form submission.
The date() function returns a string. Try converting both dates to integers first using the Date.parse() function:
date()
Date.parse()