King_Fisher
King_Fisher

Reputation: 1213

selected date of Jquery datepicker is wrong

i just Changed the year Range is 1960 to 2003

but i got current year on the textbox while I'm selecting Date for instance if i selected march-4-1960 but it displays '03/04/2015'

enter image description here

Code:

$(function() {
$( "#txt1" ).datepicker(
    {

     changeMonth: true,
            changeYear: true,
            yearRange: '1960:2003'
    });
});

HTML:

<input type="text" id="txt1"/>

Upvotes: 0

Views: 1591

Answers (2)

Rahul Desai
Rahul Desai

Reputation: 15501

One way to fix this is by setting a defaultDate. I believe this approach is much cleaner.

Updated jsFiddle

JS:

$(function() {
    $( "#txt1" ).datepicker({
        changeMonth: true,
        changeYear: true,
        yearRange: "1960:2003"
        defaultDate:"1994-01-01"
    });
});

Source

defaultDate jQuery UI documentation


Re-updated jsFiddle based on your comment.

Upvotes: 0

I&#39;m Geeker
I&#39;m Geeker

Reputation: 4637

Use this Demo here

   $(function() {
$( "#txt1" ).datepicker({    
            changeMonth: true,
            changeYear: true,
            yearRange: '1960:2003',
      onClose: function(dateText, inst) { 
         var startDate = new Date(dateText);


        var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
        var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
        $(this).datepicker('setDate', new Date(year, month, inst.selectedDay));
    }
    });
});

Upvotes: 3

Related Questions