There are two date fields namely 'Date 1' and 'Date 2'. On clicking the button 'Check', the maximum of the two dates need to be printed in the 'Max Date' field. So how to print the max date from a set of dates. I have tried pushing the date values into an array and finding out the max, but something seems wrong. Below is the HTML and javascript code.
function checkMaxDate() {
var dateArray = [];
var date1 = dateArray.push(document.getElementById('date1').value);
var date2 = dateArray.push(document.getElementById('date2').value);
var maxDate = Math.max.apply(Math, dateArray);
document.getElementById('maxdate').value = maxDate;
}
Date 1: <input type="date" id="date1" />
Date 2: <input type="date" id="date2" />
Max Date: <input type="date" id="maxdate" />
<button type="button" onclick="checkMaxDate()">Check</button>