How to make the current day appear in the field

<div class="formright"> <label for="name">Join date:</label> <input type="date" id="myDate" name="join_date" /> </div> 

    3 answers 3

    Set the valueAsDate property of the valueAsDate field to the desired value, that is, the current date:

     document.getElementById('myDate').valueAsDate = new Date(); 
     <div class="formright"> <label for="name">Join date:</label> <input type="date" id="myDate" name="join_date" /> </div> 

      I think this will help you.

       var fullDateTime = new Date(); var getNormalDate = function(date){ var day = date.getDate(); var month = date.getMonth() + 1; var year = date.getFullYear(); return month + '/' + day + '/' + year; }; document.getElementById('myDate').value = getNormalDate(fullDateTime); 
       <div class="formright"> <label for="name">Join date:</label> <input type="date" id="myDate" name="join_date" /> </div> 

      • one
        The code does not work - Alex78191
      • It can not be this, on the button execute the same works. That you probably do not use it correctly in your code - Shnur
      • one
      • Your link to the picture does not open ... ((( - Shnur

       Data = new Date(); Hour = Data.getHours(); Minutes = Data.getMinutes(); Seconds = Data.getSeconds(); // Вывод document.write("Текущее время: " + Hour + ":" + Minutes + ":" + Seconds); 

      • one
        It seems to be a little bit wrong - so you get the current time, not the date, besides the result will be written as a string in the document, and the author seems to want the result to be recorded in the <input> field - diraria
      • just like that in input and date - Valera Khomchenko