Print date in input date box in html - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Date

Description

Print date in input date box in html

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
function displayDate() {/*from  w  ww . j  a  v a 2  s  . c  o  m*/
    var now = new Date();
    var day = ("0" + now.getDate()).slice(-2);
    var month = ("0" + (now.getMonth() + 1)).slice(-2);
    var today = now.getFullYear() + "-" + (month) + "-" + (day);
    document.getElementById("fname").value = today;
}

      </script> 
   </head> 
   <body onload="displayDate()"> 
       Enter date:
      <input type="date" id="fname" readonly>   
   </body>
</html>

Related Tutorials