0

I want the calendar to automatically select the day after if a customer selects a closing day.

   var selectedday= $('#calendarid').val();
if(selectedday.getDay() == 6) $(#calendarid).datepicker('setDate', 1);

This gets me "selectedday.getDay() is not a function" as I guess that a string is being returned and not an object.

Can somebody help?

Kind regards,

1 Answers1

0

Yes, datepicker is returning a string that you have to convert to a proper date.

$('#calendarid').datepicker()

$('#calendarid').change(function() {
  selectedDate = new Date($(this).val())
  if (selectedDate.getDay() == 0) { // Changed this to sunday
    selectedDate.setDate(selectedDate.getDate() + 1)
    $(this).datepicker('setDate', selectedDate);
    $(this).blur();
  }
})
<link href="https://code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<input type="text" id="calendarid" />

However, this is potentially going to confuse the user if you don't give any warning. You can disable the selection of Sundays instead:

$('#calendarid').datepicker({
  beforeShowDay: function(date) {
    return [date.getDay() != 0, ""];
  }
})
<link href="https://code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<input type="text" id="calendarid" />

References:

msg
  • 7,863
  • 3
  • 14
  • 33