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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:09:42+00:00 2026-05-25T16:09:42+00:00

This should be quite simple but I can`t fix it :/ I am using

  • 0

This should be quite simple but I can`t fix it :/

I am using a component that displays a list of months, the upcoming 12 to be exact. However, the year does not change to 2012 when past December.

See here:
http://protekco.com/index.php/en/reservation.html

And the code that calls it:

        echo AHtml::getMonthsSelect('imonth', (int) $month, $year, $currentMonth, $currentYear, $config->calendarDeepMonth, 'onchange="Calendars.monthNavigation(this.value)"'); ?>

The $currentYear is the actual year variable that is presented on the site. I basically need someway to add +1 if we are past the end of the year. Any ideas?

Thanks!

Edit: here is the months array:

 function getMonthsSelect($name, $selectedMonth, $selectedYear, $month, $year, $deep, $attribs = '')
{
    $months = array(1 => JText::_('January') , 2 => JText::_('February') , 3 => JText::_('March') , 4 => JText::_('April') , 5 => JText::_('May') , 6 => JText::_('June') , 7 => JText::_('July') , 8 => JText::_('August') , 9 => JText::_('September') , 10 => JText::_('October') , 11 => JText::_('November') , 12 => JText::_('December'));

    $stop = $month + $deep;
    for ($i = $month; $i < $stop; $i ++)
        $arr[] = JHTML::_('select.option', ($key = (! ($k = $i % 12) ? 12 : $k)) . ',' . ($y = (floor(($i - $month) / 12) + $year)), ($months[$key] . '/' . $y));

    return JHTML::_('select.genericlist', $arr, $name, $attribs, 'value', 'text', $selectedMonth . ',' . $selectedYear);
}

Edit 3: Final solution:

function getMonthsSelect($name, $selectedMonth, $selectedYear, $month, $year, $deep, $attribs = '')
{
    $months = array(1 => JText::_('January') , 2 => JText::_('February') , 3 => JText::_('March') , 4 => JText::_('April') , 5 => JText::_('May') , 6 => JText::_('June') , 7 => JText::_('July') , 8 => JText::_('August') , 9 => JText::_('September') , 10 => JText::_('October') , 11 => JText::_('November') , 12 => JText::_('December'));

    $stop = $month + $deep;
    $wheremonth = 12 - $month;
    for ($i = $month; $i < $stop; $i ++, $wheremonth--)

    if ($wheremonth >= 0) {
        $arr[] = JHTML::_('select.option', ($key = (! ($k = $i % 12) ? 12 : $k)) . ',' . ($y = (floor(($i - $month) / 12) + $year)), ($months[$key] . '/' . $y));
        }
        else {            $arr[] = JHTML::_('select.option', ($key = (! ($k = $i % 12) ? 12 : $k)) . ',' . ($y = (floor(($i - $month) / 12) + $year+1)), ($months[$key] . '/' . $y));
        }
    return JHTML::_('select.genericlist', $arr, $name, $attribs, 'value', 'text', $selectedMonth . ',' . $selectedYear);

        }
  • 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-25T16:09:43+00:00Added an answer on May 25, 2026 at 4:09 pm

    Not sure how the inputs are working here, but you have next month and previous month. You can implement a counter variable that adds when you hit next and subtracts when you hit previous. So something like:

    $i = 1;
    
    function datetracker() {
    
    if($nextbtnclicked = true) {
         $i++;
    } elseif($prevbtnclicked = true) {
         $i--;
    }
    
    if($i == 13) {
         $i = 1;
         $currentYear += 1;
    }
    }
    

    I’m just using sample variables, but you can implement the counter in the Javascript and do the login in JS.

    EDIT: That code actually looks right. Don’t know why it’s not working, but try something like this.

    function getMonthsSelect($name, $selectedMonth, $selectedYear, $month, $year, $deep, $attribs = '') 
    { 
        $months = array(1 => JText::_('January') , 2 => JText::_('February') , 3 => JText::_('March') , 4 => JText::_('April') , 5 => JText::_('May') , 6 => JText::_('June') , 7 => JText::_('July') , 8 => JText::_('August') , 9 => JText::_('September') , 10 => JText::_('October') , 11 => JText::_('November') , 12 => JText::_('December')); 
    
        $stop = $month + $deep;
        $newyear = false;
        for ($i = $month; $i < $stop; $i ++) {
    
            if($newyear) {
            $arr[] = JHTML::_('select.option', ($key = (! ($k = $i % 12) ? 12 : $k)) . ',' . ($y = (floor(($i - $month) / 12) + $year + 1)), ($months[$key] . '/' . $y));
             $newyear = false;
            } else {
            $arr[] = JHTML::_('select.option', ($key = (! ($k = $i % 12) ? 12 : $k)) . ',' . ($y = (floor(($i - $month) / 12) + $year)), ($months[$key] . '/' . $y));
    
            }
         if($i == 12) { $newyear = true; }
         }
    
        return JHTML::_('select.genericlist', $arr, $name, $attribs, 'value', 'text', $selectedMonth . ',' . $selectedYear); 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This should be simple, but for reason I can't quite fathom it doesn't work
This should be a really simple problem, but I can't quite figure out what
All, This should be a pretty simple question, but I haven't found quite the
This should be quite a simple problem, I've come across it enough that there
This is probably quite a simple question, but I can't remember how to do
It should quite simple algorithm, but I just can't get around it. I have
This should be a really really simple thing, but for some reason it is
This should be a simple question, but I haven't been able to find a
I hope this is a simple one, but I can't seem to be able
The problem is quite simple, I have a method that returns a list. I

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.