Pre-populating date input field - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Date

Description

Pre-populating date input field

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=( function() {/*from www.  java 2  s  . co  m*/
(function () {
    var date = new Date().toISOString().substring(0, 10),
        field = document.querySelector('#date');
    field.value = date;
    console.log(field.value);
})();
    });

      </script> 
   </head> 
   <body> 
      <input id="date" type="date" value="2019-11-11">  
   </body>
</html>

Related Tutorials