views:

52

answers:

3

Hi. I want to remove the default date in my JQuery Datepicker.

I try the following code:

$(this).datepicker({defaultDate: ''});

But it doesn't seem to work. Today's date is still selected as default.

+2  A: 

To open the datepicker dialog it must be opened in some month of some year. I mean, you want to display this dialog and be blank?...

I think if you don't want to pass any default date, the best you can do is get the current date with:

$(document).ready(function() {
  $('#datepicker').datepicker();
});

Passing this will fail, because of given defaultDate, not null but blank

$(this).datepicker({defaultDate: ''});

This is something that will do what intended in the previous code

$(this).datepicker({defaultDate: null});

but it's behavior is the same as the first code block in this answer.

Garis Suero
A: 

What do you mean by wanting to "remove" the default date?

How do you think the datepicker will open up when he has no month to start from?! You have to have a default date.

Edit on your comment

Set a default date as you want and check, if the user has changed it. If so, he selected a custom date.

Another approach would be to create a variable that is set to true as soon as the user clicks on the datepicker field.

If the user submits the form, you check for that variable. If it's true, the user has selected a date. If not, he didn't touch the datepicker field.

ApoY2k
What I mean is, of course, that I dont want a selected date when the datepicker opens up. In my site, I want to make it mandatory for the user to make a choice before he can continue.
+1  A: 

What plugin are you using? Depending on the plugin, different expressions will achieve what you want:

    $(this).datepicker({defaultDate: new Date(2010, 12-1, 25)});

or

    $(this).datepicker("setDate", "<mm/dd/yyyy>");

or you could try this

   var date = new Date(); 
   date.setMonth(<month>, <day>);
   date.setYear(1900 + <#>);
   $(this).datepicker({defaultDate: date});
mjw06d
Well I was thinking you wanted to change the default date, not prevent it from displaying a default date. I believe it will always have a default date.
mjw06d