Hello everyone,

i'm using a jquery datepicker like this:

<script type="text/javascript">
$(function() {
    rangeSelect: true,
    monthsToShow: 3,
    minDate: '+7d',
    rangeSeparator: '|',
    altField: '#resdate',
    altFormat: 'dd-mm-yyyy',
    pickerClass: 'locgrid',
    onDate: nationalDays
var natDays = [[12, 18, 2010], [12, 19, 2010]]; 

function nationalDays(date, inMonth) { 
    if (inMonth) { 
        for (i = 0; i < natDays.length; i++) { 
            if (date.getMonth() + 1 == natDays[i][0] && 
                    date.getDate() == natDays[i][1] &&
                        date.getFullYear() == natDays[i][2]
                    ) { 
                return {dateClass: natDays[i][3] + '_day', selectable: false}; 
    return {}; 

now what i'm trying to accomplish is, when a user clicks a start- and enddate and there is a natDays variable in between to throw an error message.

any ideas?


I think I have it.

In the datepick settings, change onDate: nationalDays to onSelect: nationalDays .

Then nationalDays should be as follows:

function nationalDays(dates) {
	var natDate;
	var includesNatDate = false;
	for (i=0; i<natDays.length; i++) {
		d = $.datepick.newDate(natDays[i][2], natDays[i][0], natDays[i][1]);
		if(d.getTime() >= dates[0].getTime() && d.getTime() <= dates[1].getTime()) {
			includesNatDate = true;
	$("#message").html('includesNatDate : ' + includesNatDate);

In the last line, I just display a true|false message but you will do whatever is necessary in your application. There's no point returning true|false from nationalDays because it is a callBack function and you don't have access to the returned value.

Hope this helps.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.