Adrian
Adrian

Reputation: 1002

jQuery datepicker setDate to value from div

I have problem with datepicker setDate option (I need to use server date in datepicker). I have display current date from server in that format (html source):

<div id="cur-date">27/11/2013</div>

In jquery script I try to set the setDate using this code:

$('#date_from, #date_to').datepicker({
    beforeShowDay: noWeekendsOrHolidays,
    defaultDate: '+1d', 
    minDate: '+1d'
    }).datepicker('setDate', '#cur-date');

But it didn't work. Any suggestion what is wrong?

Upvotes: 0

Views: 802

Answers (3)

Rituraj ratan
Rituraj ratan

Reputation: 10378

first use text() not val()

val() is use for input type

$('#date_from, #date_to').datepicker({
    beforeShowDay: noWeekendsOrHolidays,
    dateFormat: "mm/dd/yy"
}).datepicker("setDate", $("#cur-date").text());

Upvotes: 1

AAA
AAA

Reputation: 142

Use datepicker with these parameters

$('#date_from, #date_to').datepicker({
  format: 'mm/dd/yy',
  autoclose: true,
  forceParse:true,
  pickerPosition: "bottom-left",
 startDate: $("#cur-date").text()
});

Upvotes: 0

Nibin
Nibin

Reputation: 3960

Relative dates must contain value and period pairs; valid periods are "y" for years, "m" for months, "w" for weeks, and "d" for days. For example, "+1m +7d" represents one month and seven days from today.Since you are added +1d it does not show the current date. For example 2 represents two days from today and -1 represents yesterday.

$('#date_from, #date_to').datepicker({
    defaultDate: '+1d', 
    minDate: '0'
 }).datepicker('setDate', '#cur-date');

Try removing the `minDate: '+1d'` or try commenting that part or even changing it to 0.

Working fiddle

http://jsfiddle.net/Uv8c5/

Upvotes: 0

Related Questions