Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 660947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:12:49+00:00 2026-05-13T23:12:49+00:00

I have a jquery datepicker which is renders the current date by default as

  • 0

I have a jquery datepicker which is renders the current date by default as a full calendar. Before this is rendered I get a list of days from the server via ajax of days that need to be highlighted for the current month. The code for this is as follows:

 $.get("Note/GetActionDates/?orgID=" + orgID + "&month=" + month +"&year=" + year,
        null, function(result) {
            RenderCalendar(result);
        }, "json");


function RenderCalendar(dates) {
        $("#actionCal").datepicker({ dateFormat: 'dd/mm/yy', beforeShowDay: function(thedate) {
            var theday = thedate.getDate();
            if ($.inArray(theday, dates) == -1) {
                return [true, "", ""];
            }
            else {
                return [true, "specialDate", "Actions Today"];
            }
        }
        });
    }

This is all good, but I would like the highlighted dates to update when the user clicks to a different month. I can modify the jquery datepicker initialise code with the following code:

onChangeMonthYear: function(year, month, inst) {
            //get new array of dates for that month
            $.get("Note/GetActionDates/?orgID=" + orgID + "&month=" + month + "&year=" + year,
            null, function(result) {
                RenderCalendar(result);
        }, "json");
            }

But this doesn’t seem to work.

Could anyone show me what I’m doing wrong? Thanks! 🙂

UPDATE – Working Code

Thanks for the help!

I have tweaked the code from petersendidit as follows and it now works. Gonna add a little more code to remove duplicate dates from the dates array but aside from that its all good.

$("#actionCal").datepicker({
            dateFormat: 'dd/mm/yyyy',
            beforeShowDay: function(thedate) {
                var theday = thedate.getDate() + "/" + (thedate.getMonth() + 1) + "/" + thedate.getFullYear();
                if ($.inArray(theday, actionCalDates) == -1) {
                    return [true, "", ""];
                } else {
                    return [true, "specialDate", "Actions Today"];
                }
            },
            onChangeMonthYear: function(year, month, inst) {
                dateCount = 0;
                getDates(orgID, month, year);
            }

        });

function getDates(orgID, month, year) {
        dateCount += 1;
        if (dateCount < 4) {
            $.ajax({
                url: "Note/GetActionDates/",
                data: {
                    'orgID': orgID,
                    'month': month,
                    'year': year
                },
                type: "GET",
                dataType: "json",
                success: function(result) {
                    actionCalDates = actionCalDates.concat(result);
                    getDates(orgID, month + 1, year);
                    getDates(orgID, month - 1, year);
                }
            });
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:12:49+00:00Added an answer on May 13, 2026 at 11:12 pm

    The problem is that you are making the ajax request onChangeMonthYear and re-initializing the datepicker, by the time your ajax request finishes the new month is already drawn.

    What you could do is load the “dates” for the current month and the previous and next month. Then onChangeMonthYear go fetch more dates and add that to your datesArray.

    Something like this (untested):

    var actionCalDates = array();
    function getDates(orgID, month, year) {
        $.ajax({
            url:"Note/GetActionDates/",
            data: {
                'orgID':orgID,
                'month':month,
                'year':year
            },
            type:"GET",
            dataType: "json",
            success: function(result) {
                actionCalDates.concat(result);
                getDates(orgID, month+1, year);
                getDates(orgID, month-1, year);
            }
        });
    }
    
    $("#actionCal").datepicker({ 
        dateFormat: 'dd/mm/yy',
        beforeShowDay: function(thedate) {
            var theday = thedate.getDate();
            if ($.inArray(theday, actionCalDates) == -1) {
                return [true, "", ""];
            } else {
                return [true, "specialDate", "Actions Today"];
            }
        },
        onChangeMonthYear: function(year, month, inst) {
            getDates(orgID, month, year);
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.