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 6589805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:13:17+00:00 2026-05-25T17:13:17+00:00

I am creating an events calendar in a WordPress theme using David Walsh’s calendar

  • 0

I am creating an events calendar in a WordPress theme using David Walsh’s calendar function. I want to move between months with AJAX but am unfamiliar and having trouble posting and getting the month and year variables. I am referencing this AJAX video tutorial.

At the top of the page template, I have this function:

    function swapContent(month,year) {
        jQuery("#calendar").html("<img src='images/ajax-loader.gif'>").show();
        var url="calendar.php";
        jQuery.post(url, {contentVar: month, year}, function(data){
            jQuery("#calendar").html(data).show();
        });
    }

In calendar.php:

    $month = (int) ($_GET['month'] ? $_GET['month'] : date('m'));
    $year = (int)  ($_GET['year'] ? $_GET['year'] : date('Y'));

    $contentVar = $_POST['month']['year'];

And my previous/next month controls look like this:

$previous_month_link = '<a href="?month='.($month != 1 ? $month - 1 : 12).'&year='.($month != 1 ? $year : $year - 1).'" class="control" onClick="return false" onmousedown="javascript: swapContent("month", "year")">Previous Month</a>';

All of my calendar.php file here: http://pastebin.com/R9zpA3yM

Thanks in advance, any help much appreciated.

  • 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-25T17:13:18+00:00Added an answer on May 25, 2026 at 5:13 pm

    It doesn’t look like you’re setting the month and year correctly. You’re passing in “month” and “year” as strings and then not setting them as the right parameter names to pass into your PHP script. Try this:

    function swapContent(monthVal,yearVal) {
        jQuery("#calendar").html("<img src='images/ajax-loader.gif'>").show();
        var url="calendar.php";
        jQuery.post(url, {month: monthVal, year: yearVal}, function(data){
            jQuery("#calendar").html(data).show();
        });
        return false;
    }
    

    Then in your PHP:

    $monthVal = ($month != 1 ? $month - 1 : 12);
    $yearVal = ($month != 1 ? $year : $year - 1);
    
    $previous_month_link = '<a href="?month='.$monthVal.'&year='.$yearVal .'" class="control" onClick="swapContent("'.$monthVal.'","'.$yearVal.'");">Previous Month</a>';
    

    Rather than use onmousedown I would just have the function in the onclick, just make sure it returns false at the end of the function which I’ve included.

    I am not sure how month, year and contentVar are all being used in your PHP script, so the following is an assumption, but it looks like you would just need something along the lines of:

    $month = (int) ($_POST['month'] ? $_POST['month']
                                    : ($_GET['month'] ? $_GET['month'] 
                                                      : date('m')));
    
    $year= (int) ($_POST['year'] ? $_POST['year']
                                   : ($_GET['year'] ? $_GET['year'] 
                                                      : date('Y')));
    

    And then use those variables accordingly to get your data?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am using drupal events calendar and i am creating events. Now i want
How do I select the calendar to use when creating events using the Zend
I am creating a calendar application. In the Events table, there are two columns,
I'm creating a calendar that displays a timetable of events for a month. Each
I'm creating an events website using PHP. I have a database with an events
I'm creating new events in a google calendar ( php API ) and I
I am creating an widget to access the events stored in a google calendar.
I'm creating a calendar where users can set events and time in single line,
I am creating a monthly calendar of events. Each day that has one or
Disclaimer: I'm new to web development. I'm creating an event calendar using CodeIgniter, and

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.