views:

26

answers:

2

I am trying to create two different sets of settings for datepicker(http://keith-wood.name/datepick.html) when the user picks different radiobuttons in a group.

Here's my code:

$("input[name='shipping_time_english']").change(function(){
   datepicker();                                                     
});

function datepicker() {
  if ($("input[name='shipping_time_english']:checked").val() == '1-3 work days') {
    alert('1-3 days selected');
    var firstDay = '+1';
    var lastDay = '+3';
  } else if ($("input[name='shipping_time_english']:checked").val() == '4-8 work days') {
    alert('4-8 days selected');
    var firstDay = '+4';
    var lastDay = '+8';
  }

  $("#rush_needed_by_english").datepick({
    minDate: firstDay,
    maxDate: lastDay
  }); 
} //end datepicker function

I know the change event is working, because the alerts are alerting each time I change the value of the radiobuttons. For some reason, the settings on the datepicker are whatever the first value on the radiobuttons is that I select. As soon as I change the radiobutton value again, the settings on the datepick don't change as I would like.

Why can I not update settings on datepicker using change in jQuery?

+1  A: 

I think that you need to call the date picker plugin differently:

$("#rush_needed_by_english").datepick('options', {
  minDate: firstDay,
  maxDate: lastDay
}); 
Pointy
+1  A: 

Change this

$("#rush_needed_by_english").datepick({
    minDate: firstDay,
    maxDate: lastDay
});

to

$("#rush_needed_by_english").datepick('option', {
    minDate: firstDay,
    maxDate: lastDay
});

You just got the call wrong. Recheck the documentation for the plugin here jQuery Datepicker Reference and then scroll to the functions documentation. It's the second signature there.

jitter
That's exactly what I needed. Thanks alot!
zeckdude