My goal is to be able to display the same date in two selects as in the date-picker from jquery-ui.
I have created a http://jsfiddle.net/grappler/bzPYg/3/ based off this http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerIntoSelects.html
So this is my code. In the original code if I select a new date in the date-picker the date also changes in the select buttons. Now in the new set up the date doesn’t change and I don’t know how to have the Month and Year in one field.
Thank you for any help pointing me in the right direction.
The jQuery datepicker doesn’t have your old plugins’ custom events which you were binding, hence you should use the jQuery datepicker’s
onSelectevent to update yourselects according to the selected date.Fiddle
I did some other modifications to your function as well, most notably replacing your
.attrcalls on options by a proper.valin the select elements. Both work, but you should avoid using attributes for setting dynamic properties.You may as well use
.oninstead.bind, which is the standard preferred way of binding event handlers since jQuery 1.7.I also slightly modified how you were creating the Date objects.
For the month+year select, I kept the values as they are and applied some basic arithmetic for selecting, you could as well concatenate the month with year in the values (e.g.
1-2012for Jan-2012 and replace the maths with string concatenation).