www.webdeveloper.com
Results 1 to 6 of 6

Thread: Use Javascript to click through months

  1. #1
    Join Date
    Oct 2012
    Posts
    16

    Use Javascript to click through months

    Hi guys,

    I have got a calendar together which displays the days of the month but I'd like to use a couple of javascript buttons on the page to increase and decrease the "$newdate = strtotime('+0 month', $current_month);" to allow the users to click through the different months. Well, this is how I'd do it but I'm open to suggestions on how to click through the months.

    Any help would be amazing. Thank you for reading this.

    Code:
    <?php 
    
    date_default_timezone_set('Europe/London');
    
    $current_month = time();
    
    $newdate = strtotime('+0 month', $current_month);
    
    
    $day = date('d', $newdate) ;
    $month = date('m', $newdate) ;
    $year = date('Y', $newdate) ;
    
    $first_day = mktime(0,0,0,$month, 1, $year) ;
    
    $title = date('F', $first_day) ;
    
    
     $day_of_week = date('D', $first_day) ; 
    
    
     switch($day_of_week){ 
    
     case "Mon": $blank = 0; break; 
    
     case "Tue": $blank = 1; break; 
    
     case "Wed": $blank = 2; break; 
    
     case "Thu": $blank = 3; break; 
    
     case "Fri": $blank = 4; break; 
    
     case "Sat": $blank = 5; break; 
    
     case "Sun": $blank = 6; break; 
    
     }
    
    
     $days_in_month = cal_days_in_month(0, $month, $year) ; 
    
    
     $day_count = 1;
    
    
     while ( $blank > 0 ) 
    
     { 
    
     echo "<div class=\"spacer\">
              <a href=\"#\"></a>
          </div>"; 
    
     $blank = $blank-1; 
    
     $day_count++;
    
     } 
    
    
     $day_num = 1;
    
    
     while ( $day_num <= $days_in_month ) 
    
     { 
    
     echo "<div class=\"number_block\">
              <a href=\"#\">$day_num</a>
          </div>"; 
    
     $day_num++; 
    
     $day_count++;
    
     } 
    
    ?>

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,412
    You have posted a PHP script, try asking in the PHP forum.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  3. #3
    Join Date
    Oct 2012
    Posts
    16
    Ahh okay, just thought it'd be best here as I need Javascript to manipulate it.

    Thank you

  4. #4
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,412
    Depends on what you want to do, manipulate it does not describe what your attempting to do.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  5. #5
    Join Date
    Oct 2012
    Posts
    16
    I want PHP to know which month is currently being displayed on the page so that when I click the forward arrow image on the page it moves the month to the next one.

  6. #6
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,412
    Your web page would need to have a form, the form would need to be submitted to the script that controls the return data.

    You have two ways of doing this, you can go for a plain and simpler post form that uses POST or GET, you have to decide on that path

    or

    you can go for a seamless method that uses AJAX script to replace the above method with a behind the scenes method, your return data would then need a script to update the display.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles