Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if input type="date" supports placeholder

Is it possible to detect if the browser supports input type="date" with placeholder?

like image 752
Diogo Cardoso Avatar asked Apr 30 '12 16:04

Diogo Cardoso


People also ask

How can I get current date in placeholder?

Try something like this: $('#fieldID'). attr('placeholder', new Date()); You will get the date and you can format it as required.

How do you set place holder in input type date?

The placeholder attribute does not work with the input type Date, so place any value as a placeholder in the input type Date. You can use the onfocus=”(this. type='date') inside the input filed.

What is the input type for date?

<input type="date"> <input> elements of type="date" create input fields that let the user enter a date, either with a textbox that validates the input or a special date picker interface. The resulting value includes the year, month, and day, but not the time.

How can set input type date in mm/dd/yyyy format using HTML?

To set and get the input type date in dd-mm-yyyy format we will use <input> type attribute. The <input> type attribute is used to define a date picker or control field. In this attribute, you can set the range from which day-month-year to which day-month-year date can be selected from.


1 Answers

The W3 validator says placeholder attributes are not valid on date inputs. Validating this HTML:

<!doctype html>
<title>date placeholder test</title>
<input type="date"  placeholder="enter a date">

Gives the error: "Attribute placeholder not allowed on element input at this point." ... and says you can use the attribute "placeholder when type is text, search, url, tel, e-mail, password, or number".

Also, Chrome doesn't show the placeholder for date inputs, even though it thinks the attribute exists in JS (this is roughly how Modernizr checks for attributes):

var test = document.createElement(element);
test.type = 'date';
alert('placeholder' in test);
like image 148
dave1010 Avatar answered Sep 30 '22 15:09

dave1010