Reputation: 170
$(".parent_div").delegate(".input_control", "focusin", function () {
var year = $('#this_year_input').val();
var year_text = "'" + year + ":" + year + "'";
$(this).attr("readonly", "true");
$(this).datepicker({
"dateFormat": 'mm/dd/yy',
"changeMonth": true,
"changeYear": true,
"yearRange": year_text
});
});
I am trying to restrict user by selecting dates for the year he is selecting. Reason is I have multiple datepicker controls and I need the same year that user selected once. So I provided dropdown of year and getting value from it in variable 'year'. Now this is what happens. Problem is that if 'this_year_input' has 2010, var year_text get '2010:2010' but the it doesn't work in calender control. If I replace year_text with '2010:2010' in argument, it works
Upvotes: 0
Views: 1206
Reputation: 7289
You can set it like this
$(function() {
var minYear=1990;
var maxYear=2000;
$( "#datepicker" ).datepicker({
yearRange: minYear+':'+ maxYear,
changeYear: true
});
});
Upvotes: 0
Reputation: 57095
Read yearRange
var year_text = year + ":" + year ;
or
"yearRange": year + ":" + year
Upvotes: 0
Reputation: 28763
You can give like
$(this).datepicker({
"dateFormat": 'mm/dd/yy',
"changeMonth": true,
"changeYear": true,
"yearRange": year + ":" + year
});
Upvotes: 2