Hello! There is a code:

<div class="input-inner"> <form> <input type="date" class="firstDate" name="firstDate"> <input type="date" class="secondDate" name="secondDate"> </form> </div> 

How to use JS to receive data on the go? Those. without clicking a button
Check for correct dates in the fields and comparisons of these two dates?

  var firstDate = document.getElementsByClassName("firstDate")[0].value; var secondDate = document.getElementsByClassName("secondDate")[0].value; function formatDate(date) { var dd = date.getDate(); if (dd < 10) dd = '0' + dd; var mm = date.getMonth() + 1; if (mm < 10) mm = '0' + mm; var yy = date.getFullYear() % 100; if (yy < 10) yy = '0' + yy; return dd + '.' + mm + '.' + yy; } var d = new Date(2014, 0, 30); 

Here there is such code, but I don’t put my mind on what to do with it, I would do it with jquery, but here it’s necessary on pure JS How to check this data using the formatDate function

    2 answers 2

      function onDateChange(obj) { console.log(obj.name,obj.value); } 
      <div class="input-inner"> <form> <input onchange="javascript:onDateChange(this);" type="date" class="firstDate" name="firstDate"> <input onchange="javascript:onDateChange(this);" type="date" class="secondDate" name="secondDate"> </form> </div> 

       function formatDate(date) { var firstDate = document.getElementsByClassName("firstDate")[0].value; var secondDate = document.getElementsByClassName("secondDate")[0].value; if (firstDate && secondDate) { d1 = new Date(firstDate); d2 = new Date(secondDate); var tmp = d1 - d2; if (tmp > 86400000) { document.getElementById("output").innerHTML = "<====="; } else { document.getElementById("output").innerHTML = " =====>"; }; } } 
       #output { color: red; } 
       <div class="input-inner"> <form> <input type="date" class="firstDate" name="firstDate" onchange="formatDate(this.value);"> <input type="date" class="secondDate" name="secondDate" onchange="formatDate(this.value);"> </form> </div> <span id="output"></span>