Making dates unselectable
2005/03/15 07:41
Viewed 13267 times
Replies: 1/2

I am currently attempting to utilize your calendar popup to fill in a online appointment booking form. I have customized the calendar to fit my specific needs sans one request. My appointment dates are ALWAYS full for around 7 days from the current date. I would like to make every date up to and including 7 days past the current date unselectable. Is there a way to do this? I have seen other popup calendars do this somehow but am not sure they are dhtml. Any help with the code would be appreciated. I was thinking I could work around this problem by creating a function that would add 7 days to the current date and display an alert if the user selects a date that is not far enough in advance but I would really like to make them unselectable (simular to weekend days) Thanks again...

Re: Making dates unselectable
2005/03/16 23:29
Viewed 16334 times
Replies: 1/1

Eric, add the variable and function below to your script:

var SEVENDAY = 3600 * 24 * 1000 * 7;

function disallowDatesseven(date) {
date = date.getTime();
var now = new Date().getTime();
if (date < (now + SEVENDAY)) {
//start date can't be prior to seven days from now
return true;
}
return false;
}

Be sure to add the following to the end of your Calendar.setup list:

disableFunc : disallowDatesseven //the function to call

Finally, be sure to add a comma after the previous listing above it or else it won't work in your browser. It should end up looking something like this:

Calendar.setup({
inputField : "field1", // id of the input field
button : "button1", // What will trigger the popup of the calendar
ifFormat : "%Y-%m-%d ", // format of the input field
disableFunc : disallowDatesseven //the function to call
});

last
Re[2]: Making dates unselectable
2005/03/17 08:13
Viewed 19054 times
Replies: 0/0

That works great, I do have one small problem though, when I add the "disableFunc" function I lose my "dateStatusFunc" function that was disabling my weekends. Is there a way to combine these two or call the secend one from the first? I have attatched my full test code below becase I feel I may not be making myself clear. Thanks

<script type="text/javascript" src="calendar-en.js"></script>

<!-- the following script defines the Calendar.setup helper function, which makes adding a calendar a matter of 1 or 2 lines of code. -->
<script type="text/javascript" src="calendar-setup.js"></script>

</head>
Date Requested
<form action="#" method="get">
<input type="text" name="dateselect" id="dateselect" readonly="1" />
</form>

<script type="text/javascript">
var SEVENDAY = 3600 24 1000 * 7;

function disallowDatesseven(date) {
date = date.getTime();
var now = new Date().getTime();
if (date < (now + SEVENDAY)) {
//start date can't be prior to seven days from now
return true;
}
return false;
}
Calendar.setup({
inputField : "dateselect", // id of the input field
ifFormat : "%B %e, %Y", // format of the input field
disableFunc : disallowDatesseven, //the function to call
dateStatusFunc : function (date) { // disable weekend days (Saturdays == 6 and Sundays == 0)
return (date.getDay() == 3 || date.getDay() == 0) ? true : false;
}
});
</script>

last
Google