Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initialize JQuery Datepicker with a blank value

This code still sets the field to today's date

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

    });

</script>

How do I universally configure the field to start as blank?

like image 505
Doug Chamberlain Avatar asked Jun 27 '12 14:06

Doug Chamberlain


1 Answers

If the field is showing today's date it's because of how the input field is populated. The datepicker will start with whatever value the html element has, regardless of what that is:

Demo

If you cannot control the value of the input field through changing markup, but still needs the input field to be reset, you'll have to do this manually:

$(document).ready(function () {
    $('.date').datepicker({ dateFormat: "mm/dd/yy", changeMonth: true,
        changeYear: true, yearRange: '1900:2020'
    }).val('');
});
like image 167
David Hedlund Avatar answered Oct 16 '22 11:10

David Hedlund