Q:

Two textbox dates should not be greater to current date in javascript

I have written a javascript condition for checking the date condition.
What my requirement is, I have two textbox in which I add the dates, And what I want to check is that.
My both the dates which are entered into the textbox should not be greater than Current date.
I have tried the below code but it is accepting the date which is greater than system date.
var todayDate = new Date();
   var todayMonth = todayDate.getMonth() + 1;
   var todayDay = todayDate.getDate();
   var todayYear = todayDate.getFullYear();

 var todayDateText = todayMonth + "/" + todayDay + "/" + todayYear;
    var Dt1 = document.getElementById('txtFormDt').value;
    var Dt2 = document.getElementById('txtToDt').value;
  if (todayDateText > Dt1) 
    {
        alert("System Date Should be grater than From Date");
    }
     if (todayDateText > Dt2) {
         alert("System Date Should be grater than To Date");
    }

       if (Dt2 < Dt1) {
           alert("To Date Should be grater than From Date");
           return false;
       }
       return true;
  }

A:

You can compare Date objects directly using the <, >, >= and <= operators but not == or === since Dates are also Objects. However, make sure you correctly parse the values from the inputs, e.g.

function checkDate(el) {
  var form = el.form;
  var now = new Date();
  var date = parseMDY(form.startDate.value);
  form.parsedDate.value = date;

  if (!date || isNaN(+date)) {
    form.result.value = "Invalid date";
  } else {
    form.result.value = date < now;
  }
}

// Parse string in m/d/y format
// Returns invalid date if month or day out of range
function parseMDY(s) {
  var b = s.split(/\D/);
  var d = new Date(b[2], --b[0], b[1]);
  return d && d.getMonth() == b[0]? d : new Date(NaN);
}
<form id="f0">
  Insert date (m/d/y)<input type="text" name="startDate">
  <input type="button" onclick="console.log(checkDate(this));" value="Check date">
  <br>
  Input date: <input name="parsedDate" readonly size="50">
  <br>
  Before today?<input name="result">
</form>

