views:

100

answers:

2

I have my datepicker set up like this

$("#scheduled_date_163").datepicker({
    onSelect: function(dateText, inst) {
      jQuery.get("/tasks/inplace_edit?id=scheduled_date_163&class_name=Task&value=" + dateText,  function(data){
        $('#scheduled_date_163').html(data);
        $('#scheduled_date_163').removeClass('hasDatepicker');
      })
    }
  });

$('#scheduled_date_163').datepicker( "option", "defaultDate", $.datepicker.parseDate("d m y", "31 8 2009") );

As you can see the date is hardcoded. It is supposed to be replaced with some code. However, the datepicker refuses to pick the date up! It always shows me the current date. Unable to figure out why. I even tried giving the date in string and +7 etc. But today's date itself is shown as the default date.

What could be causing this?

UPDATE

The element with scheduled_date_163 is not a textfield. Its a div.On click of which the above written datepicker javascript executes.

<div id="scheduled_date_163">
    <p class='date'>None</p>
</div>

There is not way that the div ID repeats on the page.

A: 

This works for me:

$('#scheduled_date_163').datepicker({defaultDate: $.datepicker.parseDate("d m y", "31 8 2009")});

However, this just sets a default date in the date picker itself, it won't alter the input field. For the latter, you can simply asign a value with the val() method.

(The onSelect part looks irrelevant to the problem.)

Álvaro G. Vicario
Thanks. The code given by you works for me too however, as you said, it changes the default date of the date picker itself. I don't want that. I want it for a particular instance since I have hundreds of them on the page. Also, the datepicker is not shown over an input field, but it is shown on click of a div. So I suppose the val approach won't work. Any other suggestions? Thanks.
Chirantan
IDs must be unique: if `$('#scheduled_date_163')` returns more than one object your app needs a slight redesign. Whatever, I cannot understand what you want to do. If you are doing something that's non-standard, you should at least post some HTML.
Álvaro G. Vicario
A: 

DEMO: http://jsbin.com/uqevo3/2/edit

$("#scheduled_date_163").datepicker({
   defaultDate: "31-8-2009", //OR $.datepicker.parseDate("dd mm yy", "31 8 2009")
   dateFormat: 'dd-mm-yy', // format as ##-##-####
    onSelect: function(dateText, inst) {
      jQuery.get("/../" + dateText,  function(data){
        $('#scheduled_date_163').html(data);
        $('#scheduled_date_163').removeClass('hasDatepicker');
      })
    }
  });

NOTE: not needs to declare two times the same datepicker, this is your main problem!

then if you need to set some constant options for multiple datepickers, you may want use the the Utility functions .setDefaults()

aSeptik