Although I know that this has already been taken, here is my extended solution based on Sami Zin's Idea . This used jQuery 1.6.3 and jQuery UI 1.8.16 and worked for me in Firefox 6.
$('.ui-datepicker-current').live('click', function() { // extract the unique ID assigned to the text input the datepicker is for // from the onclick attribute of the button var associatedInputSelector = $(this).attr('onclick').replace(/^.*'(#[^']+)'.*/gi, '$1'); // set the date for that input to today date var $associatedInput = $(associatedInputSelector).datepicker("setDate", new Date()); // (optional) close the datepicker once done $associatedInput.datepicker("hide"); });
You can also blur() $associatedInput and focus on the next input / selection on your page, but this is not the case in general or implementation-specific ways.
As an example, I did this on the page where I worked on the tables used for the layout (don't get me started, I know this is bad practice!):
$associatedInput.closest('tr').next('tr').find('input,select').first().focus();
GregL Sep 23 '11 at 4:22 2011-09-23 04:22
source share