1

Is it possible for me to show the placeholder in input first? Right now, I can see the placeholder when I click on the input box, but I want it so that when I load the page, the placeholder can already be read instantly.

Rather than mm/dd/yyyy, it should show birth date when page is loaded1

Thank you!

defrastriche
  • 49
  • 1
  • 1
  • 6

4 Answers4

8

<input placeholder="Your Date" type="text" onfocus="(this.type='date')" onblur="(this.type='text')" id="date">

Read this Page

How do I simulate placeholder functionality on input date field?

Community
  • 1
  • 1
  • Thank you! This is the answer I was looking for! – defrastriche Jun 12 '16 at 05:29
  • This is great, but the problem is when you leave the field and the dang date changes format from MM/DD/YYYY to YYYY-MM-DD. Any idea how to have the date stay in the former format once the control is changed back to type='text' ? – Scott Fraley Jun 14 '16 at 19:33
  • You can not change it but read this link it will be helpfull for you http://stackoverflow.com/questions/14647290/html-5-date-field-shows-as-mm-dd-yyyy-in-chrome-even-when-valid-date-is-set – Mahendra Choudhary Jun 15 '16 at 06:50
1
        var dateofbirth="01/23/1990";
        document.getElementById('test').placeholder=dateofbirth;

codepen- http://codepen.io/nagasai/pen/OXMdvr

Naga Sai A
  • 10,771
  • 1
  • 21
  • 40
1

You can overlap input date default placeholder with :before element. It is necessary that the input element is controlled with onChange event

/* When Input type="date" && value="" => hide Input content */

input[type="date"][value=""] {
  position: relative;
  height: 100%;
  color: transparent;
  transition: all 0.2s;
}


/* When focus show it*/

input[type="date"]:focus {
  color: inherit;
}


/* Input type="date" && value="" => overlap with before */

input[type="date"][value=""]:before {
  content: attr(placeholder);
  position: absolute;
  height: 100%;
  width: calc(100% - 20px);
  padding-top: 4px;
  color: #aaa;
  background-color: white;
  transition: all 0.2s;
}


/* rid off before on focus */

input[type="date"]:focus:before {
  content: none;
}
<input type="date" placeholder="My placeholder" value="" />
filoscoder
  • 495
  • 1
  • 4
  • 10
-1

http://www.htctu.net/html5/forms/formInputTypes.html#date Try this link.

<input type=date form="sf1" name="date" placeholder="23-7-1988">