Click here to Skip to main content
16,015,481 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,

I have a javascript DatePicker and I need to customise the date selection. I want to have available only fridays for selection and when the date is greater that the 15 it enables the first friday of next month as well.

So for example if the todays date is less than the 15 i want to be able to select only this months fridays if it is greater that the 15 i want to be able to select this months fridays and the first friday of next month.

Thanks for your help. I tried this code out but it didn't work
JavaScript
function pageLoad() {
           $(function () {
               $("#dp").datepicker({ dateFormat: 'dd/mm/yy', beforeShowDay: nextMonthFriday, onSelect: function (dateText, inst) { __doPostBack('DatePicker', '') } });
           })
       }

       function nextMonthFriday(date) {
       var d = new Date();
       var d1 = new Date();

       d = now.getDate();
       var d2 = d.getDay();
       if (d >= 15)
       {
           d1 = new Date(now.getFullYear(), now.getMonth() + 1, 1);
           d2 = d1.getDay();


           return[(d2 == 5 && (d1.getDate() <= 7)),''];
       }

       return [(false), ''];
       }


       function onlyFridays(date) {
           var day = date.getDay();
           var d = date.getDate();

           if (day == 5 )
               return [(date <= FridayWeek()), ''];




           return [(false), ''];
       }


       function FridayWeek()
       {
           var d = new Date();

           while (d.getDay() != 5)
           {
               d.setDate(d.getDate() + 1);
           }

           d.setDate(d.getDate() + 7);

           return d;
       }
Posted
Comments
Mahesh Bailwal 25-Aug-13 9:20am    
what's going wrong with this code?
jonhbt 25-Aug-13 16:07pm    
it is not working at all. I tried to change the event when to call the functions but no result. Thanks for the reply

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900