I'm using datetime-local
type input field to capture date/time from a user. I am fully aware that this is only supported by Chrome & Opera browser and for my application, that's completely fine.
What I am noticing is that if I start with an empty value for this input field, the changes are not reflected when I blur out of this field. However when I start with a non-empty value for this input field, the changes are reflected.
Here's my code:
HTML
<strong>Blank Date/Time (Changes are not reflected)</strong>
<br />
<input id="myDate" type="datetime-local" value="" />
<br />
Date Time Value:
<br />
<div id="myDateValue"></div>
<hr />
<strong>Non-Empty Date/Time (Changes are reflected)</strong>
<br />
<input id="myDate2" type="datetime-local" value="2016-09-16T00:00:00" />
<br />
Date Time Value:
<br />
<div id="myDateValue2"></div>
JavaScript
$(document).ready(function(e) {
$('#myDate').on('blur', function(evt) {
var dateTimeValue = document.getElementById('myDate').value;
$('#myDateValue').text('value = ' + dateTimeValue);
});
$('#myDate2').on('blur', function(evt) {
var dateTimeValue = document.getElementById('myDate2').value;
$('#myDateValue2').text('value = ' + dateTimeValue);
});
});
Here's the link for the same on jsFiddle: https://jsfiddle.net/qyyory4r/
This is happening in both Chrome & Opera.
What I am curious to know:
- Is this a known bug with this control? I tried searching for this but couldn't find anything.
- I think this input control still doesn't support
onChange
event and hence I am usingonBlur
event. Is there another way to get the changed value when starting with empty value?