9

I have the following input:

<input class="AccordionLeft" id="operationDate" name="OperationDate" type="date" value="">

This shows the date format as a default placeholder. I would like to remove this placeholder and just have an empty input field.

If I do this:

`$('#operationDate').val('@DateTime.Now.ToString("yyyy-MM-dd")');`

I get today`s date as the placeholder, but if I use this:

$('#operationDate').val('');

I get the placeholder like dd-mm-yyyy. Can the placeholder be removed entirly? I have seen several posts about changing the date format, but have found none about removing the placeholder completley.

Elad Lachmi
  • 10,406
  • 13
  • 71
  • 133
  • What you're looking for is not to change the `input` type? From `date` to `text`? Or I didn't get your question. – emerson.marini Jul 29 '14 at 15:07
  • @MelanciaUK - I am looking to remove the `mm-dd-yyyy` placeholder. The text that is displayed in the input by default, before any value is selected. – Elad Lachmi Jul 29 '14 at 15:41
  • Maybe this can help you: http://stackoverflow.com/questions/11387655/disable-new-chrome-date-types-input-formatting-and-placeholder – emerson.marini Jul 29 '14 at 15:47
  • 1
    @MelanciaUK - Thanks for the reply. I looked at that question before. I think it has more to do with the date format that is displayed. – Elad Lachmi Jul 30 '14 at 07:05
  • @Maks3w Maybe, but since my question is older, technically, that is a duplicate of this and not the other way around... – Elad Lachmi Mar 02 '16 at 08:22
  • I choose this way because the target does not have references to jQuery – Maks3w Mar 02 '16 at 08:25

2 Answers2

21

You could achieve a nice effect using onfocus and onfocusout, along with some CSS.

<input name="date" type="text" onfocus="(this.type='date')" onfocusout="(this.type='text')">
Jeroen Bellemans
  • 2,049
  • 2
  • 25
  • 42
8

You can hide the format placeholder with the following style rule:

<style>
::-webkit-datetime-edit-year-field:not([aria-valuenow]),
::-webkit-datetime-edit-month-field:not([aria-valuenow]),
::-webkit-datetime-edit-day-field:not([aria-valuenow]) {
    color: transparent;
}
</style>
<input type=date>
int32_t
  • 5,774
  • 1
  • 22
  • 20