-1

I have form and I want to set today's date in one field.

<input id="starttdate" type="date" name="startdate">

and I want to set today's date in this field, means that when this form open it show today's date in this filed by default.

My javascript code is this

var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; //January is 0!

var yyyy = today.getFullYear();
if (dd < 10) {
  dd = '0' + dd;
}
if (mm < 10) {
  mm = '0' + mm;
}
var today = mm + '/' + dd + '/' + yyyy;
document.getElementById('starttdate').value = today;
<input id="starttdate" type="date" name="startdate">
RobG
  • 142,382
  • 31
  • 172
  • 209
LOKESH
  • 1,303
  • 1
  • 16
  • 29
  • 3
    Possible duplicate of [HTML5 Input Type Date -- Default Value to Today?](https://stackoverflow.com/questions/6982692/html5-input-type-date-default-value-to-today) – CBroe Jun 12 '17 at 10:35
  • https://www.w3.org/TR/html5/infrastructure.html#valid-month-string – CBroe Jun 12 '17 at 10:35
  • Note that input type date is not well supported. You haven't asked a question, you've just shown some code that seems to work OK, at least in IE. What is your issue? – RobG Jun 12 '17 at 22:27

1 Answers1

0

in php just give value=date("Y-m-j")

<input id="starttdate" type="date" name="startdate" value="<?php echo date("Y-m-j"); ?>">
LOKESH
  • 1,303
  • 1
  • 16
  • 29