0

I am attempting to create a dynamic calendar View where I would like different actions on a page to change what day the calendar popup loads to using the .datepicker plugin. I am fairly new to jquery and was hoping that someone could provide any ideas to how I could change what day the datepicker calendar loads to. I attempted to change the "default Date:" option but nothing seemed to affect the default date.

var changedDate= '@Model.DateTime.ToShortDateString()'; // is MM/DD/YYYY format

$(document).ready(function() {
     $("#dP").datepicker({
        onSelect: function(dateText, inst) {
            selectedDate = $("input#dP").val();
            window.location = "Day?date=" + selectedDate;
        },
        minDate: 0,
        defaultDate: changedDate
    });

    $("#idDatePicker").click(function() {
        $("#dP").datepicker("show");
    });
});

This is the HTML I'm calling.

<a class="month ui-datepicker-trigger" id ="idDatePicker"> </a>
<input type="text" style="visibility:hidden" id="dP" name="dP" value=""/>
NBeers
  • 411
  • 1
  • 6
  • 11
  • And the date you're setting, it's in the future right, not in the past ? – adeneo Jan 03 '14 at 20:24
  • have a look at this: http://stackoverflow.com/questions/233553/how-do-i-pre-populate-a-jquery-datepicker-textbox-with-todays-date – Vlad Jan 03 '14 at 20:25
  • @adeneo For the most part I would like them to travel anywhere past the current day and have the Calendar reflect the date they are current viewing. So its January but if something on the page moves them to March I would like the calendar to display march. Currently it is staying on January if I change the view to March by any other Means – NBeers Jan 03 '14 at 20:49
  • As the `mindate` is set to zero, the earliest possible date you can set the datepicker to is today, any date in the past can't be set as long `mindate` is set to zero. `defaultDate` should work fine, but the format of the date is the same as the format used for the datepicker, and by default that is usually `MM/DD/YY`, and you need to pass a date that is valid according the current date format the datepicker is using. – adeneo Jan 03 '14 at 20:53
  • Seems to work fine with any future date. What seems to be the problem, again? As soon as I gave some style properties to your idDatePicker so that it was actually clickable, the code worked. – Eran Boudjnah Jan 03 '14 at 23:57

0 Answers0