views:

215

answers:

2

Hi,

besides being able to select a date from jQuery datepicker widget I also want to be able to type a date into the datepicker's textfield. But every time I type a date and hit enter, datepicker overrides my entry with today's date. I can't figure out how to have datepicker accept typed in entry.

thanks, martin

A: 

On the official jQuery UI Datepicker demo page, this just works.

If it doesn’t work for you, you could try hitting Tab instead of Enter.

Mathias Bynens
Thanks Mathias,Tab works. Thanks. The Enter doesn't though, not even on the demo page (not for me at least). martin
Martas
A: 

I also needed to be able to type 1/9/06 instead of 1/9/2006 and have it saved in MySQL as 2006-09-01 not as 0006-09-01.

Here's what I came up with:

$(function() {
  $("#date_text_field").datepicker({
    onClose: function(dateText, inst) {
      date = $.datepicker.parseDate( 'm/d/yy', dateText );
      date = $.datepicker.formatDate( 'm/d/yy', date );
      $(this).val( date );
    }
  });
});
Martas