Nick de Boom
Nick de Boom

Reputation: 23

Changing years in a self-written Javascript calendar?

I am working on a self-coded javascript calendar. So far it loads the year 2014 (using 12 buttons for every month in that year), but i want to make it load multiple years. I made two buttons for that: last_year and next_year. Sad thing is, they don't work! To me it seems logical that they must work, but i guess i missed out on something.

make_calendar loads the whole calendar.

Here is the code for those functions:

year = 2014;

function last_year(year, month) {
year = year - 1;
return year;
month = 0;
make_calendar(year, month);
}

function next_year(year, month) {
year = year + 1;
return year;
month = 0;
make_calendar(year,month);
}

here is the HTML part for the buttons:

<div id="button_nav">
<button onclick="last_year(year,0)">Last year</button>
<button onclick="make_calendar(year,0)">January</button>
<button onclick="make_calendar(year,1)">February</button>
<button onclick="make_calendar(year,2)">March</button>
<button onclick="make_calendar(year,3)">April</button>
<button onclick="make_calendar(year,4)">May</button>
<button onclick="make_calendar(year,5)">June</button>
<button onclick="make_calendar(year,6)">July</button>
<button onclick="make_calendar(year,7)">August</button>
<button onclick="make_calendar(year,8)">September</button>
<button onclick="make_calendar(year,9)">October</button>
<button onclick="make_calendar(year,10)">November</button>
<button onclick="make_calendar(year,11)">December</button>
<button onclick="next_year(year,0)">Next year</button>
</div>

If there's any additional information needed to solve this, i'll provide it. I think this is enough though. :)

Thanks for the answers in advance

Upvotes: 0

Views: 149

Answers (2)

Gabriele Petrioli
Gabriele Petrioli

Reputation: 195982

Remove the return year; line from both functions.

They end the function and the following code is never executed.

Upvotes: 2

DebbieMiller
DebbieMiller

Reputation: 452

The lines afterreturn year; do not excute at all! Put this statment at the end of the function.

Upvotes: 2

Related Questions