ling.s ling.s - 1 year ago 134
HTML Question

JQuery datepicker yearrange

I have 2 datepickers like this

<input type="text" class="datepicker" data-year-range="2010:2016"/>
<input type="text" class="datepicker" data-year-range="2000:2020"/>

I have to define the
for the 2 datepickers in configuration. So, I did like this.

changeYear: true,
// $(this) isn't working here
//yearRange : $(this).attr('data-year-range'),
yearRange : $('.datepicker').attr('data-year-range')

But it is taking only
for the two datepickers. I don't understand why. The idea is to use different date ranges for the datepickers. Is it possible or do I need to define different datepickers?

Also, In datepickers is it possible to add the
in html instead of the datepicker configuration?

Here is the fiddle

Answer Source

You can do it in following way:

$(document).ready(function() {
     $('.datepicker').each(function() {
         changeYear: true,
         yearRange: $(this).data('year-range'),