JSFiddle - React, Tailwind, and code Playground

by Vladimir Vozar

HTML

<div class="entry">
	<label for="startDate">Start date:</label>
	<input id="startDate" name="startDate" type="date" oninput="validDate(startDate)">
</div>

JavaScript

function validDate(date) {
	todayDate = getTodaysDate();
	if (date > todayDate)
		document.searchForm["date"].value = todayDate;
}

function getTodaysDate(){
	date = new Date();
	day = date.getDate();
	month = date.getMonth() + 1;
	year = date.getFullYear();

	if (month < 10) month = "0" + month;
	if (day < 10) day = "0" + day;

	today = year + "-" + month + "-" + day;	
	
	return today;
}