user525146
user525146

Reputation: 3998

why can't datepicker accept my date string in IE 7

My code works fine in Chrome and firefox. I am not able to get it working in IE compatibility mode. If I put the maxDate: new Date(2012 AUG 28) it works in IE but if I give the newDateString, changing months is disabled. jsfiddle

endDate = "2012-09-11";
var m_names = new Array("JAN", "FEB", "MAR", 
                            "APR", "MAY", "JUN", "JUL", "AUG", "SEP", 
                            "OCT", "NOV", "DEC");

var toDate = Date.parse(endDate) - 2592000000; 
var newToDate = new Date(toDate);

newDateString = newToDate.getFullYear() + " " + m_names[newToDate.getMonth()] + " " + newToDate.getDate();

$('#datepicker').datepicker({
     showOn: "both",
     maxDate: new Date(newDateString ),
     showAnim: "slide", 
     buttonImageOnly: true,
     dateFormat: "yy-mm-dd",
     onSelect: function(dateTxt, inst) {
         $('#<DateForm').submit(); 
     },
     buttonText: ""
 });

$('#datepicker').datepicker("setDate", startDate);

UPDATE:

I have modified code to use $.datepicker.parseDate. I get an error in IE. It works fine in chrome and firefox

newDateString = newToDate.getFullYear() + " " + m_names[newToDate.getMonth()] + " " + newToDate.getDate();  

alert($.datepicker.parseDate('yy-mm-dd', newDateString));

Message: Exception thrown and not caught Line: 192 Char: 21310 Code: 0

localhost:80/jquery-ui-1.8.18.custom.min.js

Upvotes: 0

Views: 396

Answers (1)

Barmar
Barmar

Reputation: 780909

The date formats recognized by Date.parse vary between implementations. Instead, use $.datepicker.parseDate.

See http://docs.jquery.com/UI/Datepicker/parseDate for documentation.

Here's how to use this to subtract 30 days from the date:

var toDate = $.datepicker.parseDate('yy-mm-dd', endDate);
toDate.setDate(toDate.getDate()-30); /* Subtract 30 days */

Upvotes: 1

Related Questions