-2

Here is a picture of my calendar: https://imgur.com/a/XBYtSLf - imgur is down atm so idk if it will load for you :/

What I want to be able to do is click on the left or right arrows each of which call a php function in my external php doc Calendar.php

Here's the HTML Code for the Header part of the calendar:

<div class="AvailabilityCalender">

    <div class="month_header">
        <ul>
            <li class="previous_month" href = "<?= previous_month()" ?> >&#10094;</li>
            <li class="next_month" href = "<?= next_month()"> ?> &#10095;</li>
            <li><?= $month ?>
                <br>
                <span class="year"><?= $year ?></span>
            </li>
        </ul>
    </div>

Now I know that the href is looking for a file called next_month but how do I get it to call the function in my php doc:

function previous_month(){
echo 'previous month';
}

Thanks in advance Cameron

Cameron Ward
  • 25
  • 1
  • 13

1 Answers1

3

You can't do that with php. You want to manage a event, and php as a server-side language can't manipulate that, you should put in the href the link to the file you want to handle the request, for example

<a href="handlenextmonth.php"></a>
<a href="handleprevmonth.php"></a>

and have a handlenextmonth.php and handleprevmonth.php file with a call to your previous_month or next_month method

If not you should go for an javascript aproach where you could do something like

<a onclick="handlenextmonth()"></a>
<a onclick="handleprevmonth()"></a>
Howard P
  • 258
  • 3
  • 19
Carlos Salazar
  • 1,818
  • 5
  • 25
  • 48
  • Ahhh thanks, this clears it up :) – Cameron Ward Aug 28 '18 at 19:52
  • At the very least I would include a snippet about AJAX in your question. It appears my comment has been deleted for seemingly no reason, and it should be displayed somewhere. The objective of this site is to inform and be helpful which was my intention. AJAX is a very useful tool so it should be a part of this answer as a valuable asset. – Howard P Aug 30 '18 at 14:47