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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:43:53+00:00 2026-06-01T13:43:53+00:00

I am trying to call Ajax with jQuery and need to pass a variable

  • 0

I am trying to call Ajax with jQuery and need to pass a variable that is set with PHP on the page load, to two separate functions to either move my calendar forward or backwards by the months.

var ajax_load = "Loading...",
    loadUrl = "calendar_backend.php",
    month = parseInt(<?php echo $month ?>);
    console.log(month);
    month = <?php echo $month ?>;

$("#calendar_box").on("click",'#next_month',function(){  
    console.log(month);
    $("#calendar")  
        .html(ajax_load)  
            .load(loadUrl, "month=" + month + "&go=next");
    var month = ++month;

    console.log(month);
});

$("#calendar_box").on("click",'#previous_month',function(){  
    $("#calendar")  
        .html(ajax_load)  
            .load(loadUrl, "month" + month + "&go=previous");  
    var month = --month;
});

I have the console calls in there to try to debug this and I get 4 from the first .log() undefined from the second one, and NaN from the third. From those three I can see that the variable is not getting passed into the .on() handler function.

The calender generating page is included_once on the index page and then the AJAX would be used to regenerate the correct data for the month. I need the month passed in the get string to know how far from the current month i need to offset.

Thanks for the help!!

  • 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-06-01T13:43:54+00:00Added an answer on June 1, 2026 at 1:43 pm

    Simply don’t use the var keyword inside the function body. var will instanciate a new variable inside the success function. And you using the decress/incresse operator wrong, its only month++; and month--;

    var ajax_load = "Loading...",
        loadUrl = "calendar_backend.php",
        month = parseInt(<?php echo $month ?>);
        console.log(month);
        month = <?php echo $month ?>;
    
    $("#calendar_box").on("click",'#next_month',function(){  
        console.log(month);
        $("#calendar")  
            .html(ajax_load)  
                .load(loadUrl, "month=" + month + "&go=next");
        month++; // Removed var and incressing
    
        console.log(month); 
    });
    
    $("#calendar_box").on("click",'#previous_month',function(){  
        $("#calendar")  
            .html(ajax_load)  
                .load(loadUrl, "month" + month + "&go=previous");  
        month--; // Removed var and decressing
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I trying to call 2 functions in the same page to submit jquery-ajax at
I am trying to pass a dataString to to an ajax call using JQuery.
Im using jquery to call a page via ajax. I have some jquery functions
I'm fairly new with jQuery, and I'm trying to call two functions on successful
I'm trying to to make AJAX call with the jQuery library using the $.ajax()
i am trying to make a ajax call by making use of jquery UI
So I am trying to use jQuery to insert data from an ajax call.
I trying to make my first AJAX with JSON call using jQuery and CodeIgniter.
I need to perform asp.net web-service function call via jQuery and pass asp.net application
I'm trying to call a server-side action in a controller from jQuery: $.ajax({ url:'http://localhost:88/admin/business/11/GetChildBusinessTypes',

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.