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

1
  • what is your expected default value ? Commented Aug 29, 2013 at 5:25

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I have been using this code. I updated it and it have working.
@Coelho Oh, you got it. out of curiosity, can you share it in JSFiddle?
1

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

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

It will reset to default.

Comments

0

I think that there are a pair of brackets missing:

$('#EstimateTime').val(("mm/dd/yyyy --:-- --"));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.