I´m trying to add some functionality to a form with JQuery UI´s Datepicker.
When a user selects the arrival date (onSelect), a few things should happen:
Update the departure to 3 days after the arrival date(This works now :))- Split the departure date in 3 and add each part to an input field (see arrival date example in Fiddle)
- When the arrival-datepicker closes (onClose), the departure-datepicker should open automatically, defaulting to the date selected in point 1 (example: http://www.kayak.es )
I managed to get point 1 to work, but I´m a bit lost with the other features. If anyone can show me how to do this or get me on the right track that would be really great! I´m still a beginner but learning fast.
Here´s a Fiddle of what I have now: http://jsfiddle.net/mattvic/B6Kax/13/
Looks like you already have the code written for this in the
onSelecthandler of the destination datepicker. Unfortunately, it looks likesetDatedoes not trigger that event, and you cannot trigger it manually. What I would recommend is breaking that code out into a separate function that you can call from both places:Then change your departure datepicker
onSelecthandler to point to that function:Lastly, call that function from your arrival’s
onSelectevent handler:This is just a matter of using the
onCloseevent handler:Here’s your updated example: http://jsfiddle.net/zXMke/