Reputation: 1213
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'
Code:
$(function() {
$( "#txt1" ).datepicker(
{
changeMonth: true,
changeYear: true,
yearRange: '1960:2003'
});
});
HTML:
<input type="text" id="txt1"/>
Upvotes: 0
Views: 1591
Reputation: 15501
One way to fix this is by setting a defaultDate
. I believe this approach is much cleaner.
JS:
$(function() {
$( "#txt1" ).datepicker({
changeMonth: true,
changeYear: true,
yearRange: "1960:2003"
defaultDate:"1994-01-01"
});
});
defaultDate
jQuery UI documentation
Re-updated jsFiddle based on your comment.
Upvotes: 0
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