$(document).ready(funct...">

Initialize jquery datepicker with empty value

This code still sets the field to date.

<script type="text/javascript">
    $(document).ready(function () {
        $('.date').datepicker({ dateFormat: "mm/dd/yy", changeMonth: true,
            changeYear: true, yearRange: '1900:2020', defaultDate: ''
        });

    });

</script>

How to universally configure a field to run as empty?

+5
source share
1 answer

If the field shows the date today, this is due to how the input field is filled. Datepicker will start with any value that the html element has, no matter what it is:

Demo

If you cannot control the value of the input field by changing the markup, but still the input field must be reset, you will have to do it manually:

$(document).ready(function () {
    $('.date').datepicker({ dateFormat: "mm/dd/yy", changeMonth: true,
        changeYear: true, yearRange: '1900:2020'
    }).val('');
});
+15
source

All Articles