开发者

disable dates in jQuery datepicker with dates from MySQL

开发者 https://www.devze.com 2023-03-10 09:14 出处:网络
I\'m trying to disable certain dates from jQuery datepicker. I know this subject is talked about often but usually only in regards to regulars dates such as holidays or weekends. I\'d like to pull the

I'm trying to disable certain dates from jQuery datepicker. I know this subject is talked about often but usually only in regards to regulars dates such as holidays or weekends. I'd like to pull the days from a MySQL table instead. For disabling regular dates the codes is;

$(function() {
  $("#datepickerthing").datepicker({ 
    altField: '#actualDate', 
    minDate:'0', 
    maxDate: '+6M',
    beforeShowDay:  nationalDays
  });

  var natDays = ["4/22/2009","4/23/2009","4/24/2009","4/25/2009","4/26/2009","5/27/2009","5/28/2009","6/26/2009","6/27/2009","6/28/2009","6/29/2009","6/30/2009"];
  function nationalDays(date) {
    var sDate = (date.getMonth()+1).toString() + "/" + date.getDate().toString() + "/" + date.getFullYear().toSt开发者_Python百科ring();
    if ($.inArray(sDate, natDays) != -1) return [false,"","Not this day!"];
    else return [true, ""];
  }
}); 

What I don't understand is how to get a string of dates from a database into the variable "natDays" and make sure they are formatted properly.

Thanks in advance for any help anyone can offer.


You'll need to make an Ajax request.

  1. Script in PHP to create a string of properly formatted dates from your database
  2. Return this string from the ajax request
  3. .split() them into your array variable.

To properly format your dates, I'd recommend explode()ing them from your database, then dropping them into something like date("m/d/y",mktime(0,0,0,4,5,2010)) (the 4,5,2010 comes from your exploded date).

0

精彩评论

暂无评论...
验证码 换一张
取 消