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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T21:18:33+00:00 2026-06-18T21:18:33+00:00

Here I have below a full html page for a calendar creation, copy it

  • 0

Here I have below a full html page for a calendar creation, copy it over to see what it does.
I have two buttons below that can increment month by one. My problem is because I can instantiating var month= date.getMonth() at the top of the page, the global variable month only allows me to increment and decrement by 1, how can I let month be set as a local variable so I am able to increment to more than just 1. Here is the code: I’m sure copy paste will work:

Below I have posted my my button handlers to increase month/decrease month.

<script type="text/javascript"> 

printCalendar(year,month,divDestination);
function printCalendar(year,mth,divDestination){
var currentmonth = mth;
var myOutput=document.getElementById(divDestination)
myOutput.innerHTML=makeCalendar(year,mth)
}
function prevMonth(m){
    m--;
    var currentmonth = m;
    alert(m);
    if(m < 0)
    {
        m = 11;
        year--;
    }

    printCalendar(year,currentmonth,divDestination);
}
function nextMonth(m){
    m++;    
    var currentmonth = m;
    if(m > 11)
    {
        m=0;
        year++;
    }
    printCalendar(year,currentmonth,divDestination);
}
function test(div){
var myOutput=document.getElementById("divCalendar")
myOutput.innerHTML += eventmonth;
}
</script>

<div align="center" id="divCalendar"></div>
<div align="center" id="myButtons">
<input type="button" onclick="test('divCalendar')" value="Say hi" />
<input type="button" onclick="prevMonth(month,'divCalendar')" value="Previous"/>
<input type="button" onclick="nextMonth(month,'divCalendar')" value="Next" />
<input type="button" onclick="printCalendar(year,month,'divCalendar')" value="Reload Calendar" />

Here below is my makeCalendar function

var myDate = new Date();
    var month = myDate.getMonth();
    var year = myDate.getFullYear();
    var divDestination="divCalendar";

    function leapYear(yr) { 
        if (yr < 1000) yr+=1900
        return((yr%4 == 0) && ((yr%100 == 0) || (yr%400 ==0)))
    }

    function startCol(width, height, color){
        return('<TD WIDTH=' + width + ' HEIGHT=' + height + '>' + '<FONT COLOR="' + color + '">');
    }

    function getHoliday(monthSelected,theday)
    {
        monthSelected = monthSelected + 1
        var holiday = ""
        var HolidayName = new Array (1, 1, "New Year's Day",7, 1, "Canada Day",12, 25, "Christmas Day",12, 26, "Boxing Day", 2,14,"Valentine's Day")
        for(var index = 0; HolidayName.length >= index; index++)
        {   
            if(HolidayName[index] == monthSelected && HolidayName[index+1] == theday)
            {
                holiday = HolidayName[index+2]
            }
        }
        return holiday
    }

    function makeCalendar(yr, mth)
    {
        var monthSelected = mth
        var months    = new Array("Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec")
        var days      = new Array(31, leapYear(yr)?29:28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
        var weekDays  = new Array("Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat")

        var mthSz         = days[mth]
        var mthName       = months[mth]
        var firstDyofMnth = new Date(yr, mth, 1)
        var firstDay      = firstDyofMnth.getDay() + 1
        var numRows       = Math.ceil((mthSz + firstDay-1)/7)
        var mthNameHeight = 50

        var borderWidth   = 2
        var cellSpacing   = 4 
        var cellHeight    = 80 

        var hdrColor      = "midnightblue" 
        var hdrSz         = "+3" 
        var colWidth      = 100 

        var dayCellHeight = 25 
        var dayColor      = "black" 
        var dayCtr        = 1

        // Build the HTML Table 
        var txt = '<CENTER>'
        txt += '<TABLE BORDER=' + borderWidth + ' CELLSPACING=' + cellSpacing + '>' 

        //Show Month Name and Year
        txt += '<TH COLSPAN=7 HEIGHT=' + mthNameHeight + '>' 
        txt += '<FONT COLOR="' + hdrColor + '" SIZE=' + hdrSz + '>' 
        txt += mthName + ' ' + year + '</FONT>' + '</TH>'

        // Show Days of the Week 
        txt += '<TR ALIGN="center" VALIGN="center">'
        for (var dy = 0; dy < 7; ++dy) {
            txt += startCol(colWidth, dayCellHeight, dayColor) + weekDays[dy] + '</FONT></TD>' 
        }
        txt += '</TR>'

        // Show Dates in Calendar
        for (var row=1; row <= numRows; ++row) 
        {
            txt += '<TR ALIGN="right" VALIGN="top">'
            for (var col = 1; col <= 7; ++col) 
            {
                if (((col < firstDay) && (row==1)) || (dayCtr>mthSz))
                    {txt += '<TD BGCOLOR="Gainsboro"><BR></TD>'}
                else
                    {
                        var event = getHoliday(monthSelected, dayCtr)
                        txt += '<TD HEIGHT=' + cellHeight + '><FONT COLOR="' + dayColor + '"> <B>'
                        txt += dayCtr
                        txt += '</B></FONT><BR>' + event + '</TD>'
                        dayCtr++;
                    }       
            }
            txt += '</TR>'
        }
        // close all basic table tags and output txt string
        txt += '</TABLE></CENTER>'  
        return txt
        }
  • 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-18T21:18:34+00:00Added an answer on June 18, 2026 at 9:18 pm

    Lets try to trim this down further to the money bits. Here’s basically what you are doing.

    var month = new Date().getMonth()
    
    var nextMonth = function(m) {
      m++;
      setMonthSomewhere(m);
    };
    
    nextMonth(month);
    

    So what happens is that you pass your global, which is accessible everywhere anywhere, to the nextMonth() function. And function arguments basically declare a local variable, which is sets to the passed in value. You now have a global month variable set to 1, and a totally different m local to the nextMonth() function also set to 1. You then increment the local variable m to 2, which has no effect on the global variable.

    Instead, simply don’t pass it in. Manipulate the global directly.

    var month = new Date().getMonth()
    
    var nextMonth = function() {
      month++;
      setMonthSomewhere(month);
    };
    
    nextMonth();
    

    Now nextMonth() increments the global month variable directly, changing it’s value.

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

Sidebar

Related Questions

hey everyone, here is the site SEE BELOW I have a slight jquery problem
Trying not to lose it here. As you can see below I have assigned
I have a question, here are two classes below: class Base{ public: virtual void
Here's my problem: I have an HTML table that looks like this: What I
I have a .Net 2.0 activex control that is embedded within an HTML page
I have below code.The logic here is if HostList conatains any blanck entry it
Hey all. Here is the scenario. I have the below code, and I'm needing
I have the following sample dataset (below and/or as CSVs here: http://goo.gl/wK57T ) which
I have some code as shown below: - (IBAction)startButtonPressed:(id)sender { statusText.text = @Processing...; //here
I have an xml as below < Image>ImageValue1 <Type>png</Type> <Value>ImageValue1</ Value> </ Image> Here

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.