JSFiddle - React, Tailwind, and code Playground

HTML

<form id="price_analysis">
    
    <label for="from">From date:</label>
    
    <input id="from" class="datepicker from" type="text" value="" />
    
    <label for="to">To date:</label>
    
    <input id="to" class="datepicker to" type="text" value="" />    
    
    <input id="chartUpdateButton" type="submit" value="Update Chart" />
    
</form>

JavaScript

$.icisBoard = {};

// From date - default is today's date minus one year
$('#price_analysis .from').datepicker({
    constrainInput: true,
    dateFormat: 'dd/mm/yy',
    defaultDate: '-1y',
    gotoCurrent: true,
    hideIfNoPrevNext: true,
    minDate: '-1y',
    maxDate: 0,
    showOn: 'both'
});

// To date - default to today's date
$('#price_analysis .to').datepicker({
    constrainInput: true,
    dateFormat: 'dd/mm/yy',
    defaultDate: new Date(),
    gotoCurrent: true,
    hideIfNoPrevNext: true,
    minDate: '-1y',
    maxDate: 0,
    showOn: 'both'
});

$('#chartUpdateButton').live('click', function() {
    
    $.icisBoard.$formatFromDate = $('#price_analysis .from').val();

    $.icisBoard.$formatToDate = $('#price_analysis .to').val();

    if (!dateRangeIsValid()) {
        alert('Not a valid date range');
    }
    else {
        alert('This is now a valid date range!');
        //loadChart();
        //closeFlyout();
    }
    return false;
});

function dateRangeIsValid() {

    var currentDate = Date.parse(new Date());
    var fromDate = Date.parse($.icisBoard.$formatFromDate);
    var toDate = Date.parse($.icisBoard.$formatToDate);
    
    alert(currentDate);
    alert(fromDate);
    alert(toDate);
    
    if (isNaN(fromDate) || isNaN(toDate) || fromDate > toDate || fromDate > currentDate || toDate > currentDate) {
        return false;
    }
    else {
        return true;
    }
}