2

How I can reset the value for a Datatime-local to a default value : "mm/dd/yyyy --:-- --"

<script type="text/javascript">
    function addMinutes(date, minutes) {
        var newdate = date.getTime() + minutes * 60000
        var temp = new Date(newdate).toISOString();
        return temp.toString().substr(0, 19);
    }

    $('#SelectIssuePriority').change(function () {
        var selectedValue = $(this).val().split('|');
        if (selectedValue != null && selectedValue != '') {
            var newDate = addMinutes(new Date(), selectedValue[1]);
            $('#EstimateTime').val(newDate);
        } else {
            $('#EstimateTime').val("mm/dd/yyyy --:-- --");
        }
    });
</script>

I put this code to work: jsfiddle.net/2BfnE

AFetter
  • 3,355
  • 6
  • 38
  • 62

3 Answers3

2

I think it not possible to change the date format of HTML5 input type=“date”.

On a quick research I found out this SO question is some what similar to yours.

Since you have tagged jQuery why don't you use the the Datepicker of jQuery UI. Where it is quite easy to deal with formats.

Community
  • 1
  • 1
Praveen
  • 55,303
  • 33
  • 133
  • 164
1

It's simple, try this instead, just leave it empty:

$("#EstimateTime").val("");

It will reset to default.

0

I think that there are a pair of brackets missing:

$('#EstimateTime').val(("mm/dd/yyyy --:-- --"));
pap
  • 123
  • 1
  • 2
  • 14