Skip Navigation

[Resolved] Get datepicker value onClose

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to access the selected date value in a datepicker field using the onClose event.

Solution: You can access the selected day, month, and year in the second parameter of the callback function. Here's an example:

jQuery(document).ready(function(){
  jQuery('input[name="wpcf-start-date[display-only]"]').datepicker("option", "onClose", function(dateText,inst){
    console.log(inst.selectedDay + ' ' + inst.selectedMonth + ' ' + inst.selectedYear);
  });
});

Keep in mind that in JavaScript month is a zero-based index, so August will be 7.

Relevant Documentation:
http://api.jqueryui.com/datepicker/#option-onClose
https://www.w3schools.com/js/js_date_methods.asp

This support ticket is created 5 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 1 reply, has 2 voices.

Last updated by Christian Cox 5 years, 8 months ago.

Assisted by: Christian Cox.

Author
Posts
#1093873

Hi,

I'm trying to do the same thing, but I have some problem :

- First if we use :

jQuery('input.hasDatepicker').datepicker('option','onSelect',function(){
    console.log('select');
  });

It appears that all defaults options are removed (default dateFormat ...), so it seems we have to use onClose event to avoid to overwrite defaults toolset datepicker actions previously defined.

- So using onClose, I'm not able to retrieve datepicker value ? Can you help me with that ?

Thank you very much for your help
Best regards

#1093945

You can access the selected day, month, and year in the second parameter of the callback function. Here's an example:

jQuery(document).ready(function(){
  jQuery('input[name="wpcf-start-date[display-only]"]').datepicker("option", "onClose", function(dateText,inst){
    console.log(inst.selectedDay + ' ' + inst.selectedMonth + ' ' + inst.selectedYear);
  });
});

Keep in mind that in JavaScript month is a zero-based index, so August will be 7.
https://www.w3schools.com/js/js_date_methods.asp

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.