Is it possible to detect if the browser supports input type="date"
with placeholder
?
Try something like this: $('#fieldID'). attr('placeholder', new Date()); You will get the date and you can format it as required.
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.
<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.
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With