'Turn on Today button on date picker
I am using a date picker from this source http://jqueryui.com/datepicker/#buttonbar , I am trying to let "Today" button on the button bar to be active, can any one help me please.
$(".datepicker").datepicker({
showButtonPanel: true, closeText: 'Clear',
gotoCurrent : true,
changeMonth: true,
changeYear: true,
yearRange: '1900, 2300',
dateFormat: _DateFormatDatePicker,
onSelect: function (dateText, inst) {
dateAsString = dateText; //the first parameter of this function
var dateAsObject = $(this).datepicker('getDate'); //the getDate method
document.getElementById('<%=hdnTempDate.ClientID%>').value = dateText;
}
Solution 1:[1]
Try this:
$(".datepicker").datepicker({
showOn: "button",
showButtonPanel: true,
buttonImage: buttonCalendar,
buttonImageOnly: true,
buttonText: ""
});
and call this js code in the pages where you have the calendar.
$.datepicker._gotoToday = function(id) {
$(id).datepicker('setDate', new Date()).datepicker('hide').blur();
};
Solution 2:[2]
Try this
$(function() {
$( "#datepicker" ).datepicker({
showButtonPanel: true
});
});
Solution 3:[3]
Enable the Buttons panel by: showButtonPanel: true. Then place the following code after your datepicker JS code:
var _gotoToday = jQuery.datepicker._gotoToday;
jQuery.datepicker._gotoToday = function(a){
var target = jQuery(a);
var inst = this._getInst(target[0]);
_gotoToday.call(this, a);
jQuery.datepicker._selectDate(a, jQuery.datepicker._formatDate(inst,inst.selectedDay, inst.selectedMonth, inst.selectedYear));
};
Solution 4:[4]
Insert this code instead.
todayBtn: "linked",
And a bonus code that clear the input field
clearBtn: true,
Final code:
$(".datepicker").datepicker({
showButtonPanel: true,
closeText: 'Clear',
todayBtn: "linked",
clearBtn: true,
gotoCurrent : true,
changeMonth: true,
changeYear: true,
yearRange: '1900, 2300',
dateFormat: _DateFormatDatePicker,
onSelect: function (dateText, inst) {
dateAsString = dateText; //the first parameter of this function
var dateAsObject = $(this).datepicker('getDate'); //the getDate method
document.getElementById('<%=hdnTempDate.ClientID%>').value = dateText;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | periback2 |
| Solution 2 | Linga |
| Solution 3 | helencrump |
| Solution 4 | wakawakapogsSr |
