Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get selected date in jqueryui datepicker inline mode

Tags:

I am trying to use jqueryui datepicker. I want to use the inline mode.

I want to know how can I get the selected date when user selects a date. Where to get and how to get ?

like image 612
Shyju Avatar asked Oct 26 '09 13:10

Shyju


People also ask

How can I select current date in datepicker?

To set current date in control to which jQuery UI datepicker bind, use setDate() method. Pass date object which needs to be set as an argument to setDate() method. If you want to set it to current date then you can pass 'today' as argument.

How do I highlight a specific date in datepicker?

Define beforeShowDay within datepicker() method. In the function create a new date format according to the defined format (dd-mm-yyyy) in an Array. Check for the date in the Array with $. inArray() method if it is available then return [true, "highlight", tooltip_text]; otherwise return [true] .

How do I show only future dates in datepicker?

To make any past dates disable or for only future dates, you first have to find the instantiation of the datepicker, and set the startDate setting to '+0d'.


1 Answers

You can retrieve the date by using the getDate function:

$("#datepicker").datepicker( 'getDate' ); 

The value is returned as a JavaScript Date object.

If you want to use this value when the user selects a date, you can use the onSelect event:

$("#datepicker").datepicker({    onSelect: function(dateText, inst) {        var dateAsString = dateText; //the first parameter of this function       var dateAsObject = $(this).datepicker( 'getDate' ); //the getDate method    } }); 

The first parameter is in this case the selected Date as String. Use parseDate to convert it to a JS Date Object.

See http://docs.jquery.com/UI/Datepicker for the full jQuery UI DatePicker reference.

like image 176
Tim Van Laer Avatar answered Oct 07 '22 17:10

Tim Van Laer