views:

101

answers:

2

i have a certain dates that come from database and want to block those dates from selecting, how would i do that? like Alert when certain days are clicked on the jquery datepicker?

i am using asp.net C#. and pass the dates from server side to client?

any help?

A: 

I think you would have to use the onSelect event of the datepicker to do this.

Per Jquery Documentation:

$('.selector').datepicker({
   onSelect: function(dateText, inst) { //check for date and show alert }
});

HTH

Raja
i am more interested to know returning the data from server to client
Abu Hamzah
You can use Jquery .ajax and return all the dates to be stored in the client end (say a hidden control).
Raja
@Raja: can you show me some sample lines how would you go after?
Abu Hamzah
Check out Jquery documentation here: http://api.jquery.com/jQuery.ajax/
Raja
its interesting that you think it can be done (not sure how) but other says it cant (http://stackoverflow.com/questions/2695961/jquery-datepicker-disable-federal-holidays). if you have done similar then share me how you have achieved and very much interested to know.
Abu Hamzah
I totally agree with them. There is no such thing as disabling a date in the datepicker. Your question was to give out an alert. The way you do it is when the date is selected (using select method) you check it with predefined dates (say federal holiday which you bring it using ajax) and give out an alert that the date cannot be picked. HTH
Raja
A: 

var disabledDates = ['04/30/2010', '05/01/2010'];

$(function(){

$('#datepicker').datepicker({ 

    dateFormat: 'dd/mm/yy', 
    beforeShowDay: editDays 
}); 

function editDays(date) { 
    for (var i = 0; i < disabledDates.length; i++) { 
        if (new Date(disabledDates[i]).toString() == date.toString()) {              
             return [false]; 
        } 
    } 
    return [true]; 
 }    

});

Abu Hamzah