0

I have two <a></a> tags which holds the onclick event and has PHP code in it. Obviously I need them to work. What those links do - switch between months. Here are the links.

<a href="javascript:void(0);" onclick="getCalendar('calendar_div','<?php echo date("Y",strtotime($date.' - 1 Month')); ?>','<?php echo date("m",strtotime($date.' - 1 Month')); ?>');"><span class="glyphicon glyphicon-chevron-left"></span></a>
<select name="month_dropdown" class="month_dropdown dropdown"><?php echo $this->getAllMonths($dateMonth); ?></select>
<select name="year_dropdown" class="year_dropdown dropdown"><?php echo $this->getYearList($dateYear); ?></select>
<a href="javascript:void(0);" onclick="getCalendar('calendar_div','<?php echo date("Y",strtotime($date.' + 1 Month')); ?>','<?php echo date("m",strtotime($date.' + 1 Month')); ?>');"><span class="glyphicon glyphicon-chevron-right"></span></a>

As you can see I have the $this-> pointer in <select></select> tags which allows it to be in use because I am using classes and there has to be the pointer there I assume. So how do I get the tags to work? When I add the $this-> pointer to the onclick event in front of getCalendar the PHP code just breaks down.

Do I have to use some other method in order to achieve what I am after?

4
  • Edit your code to make more readable please Commented Jun 1, 2018 at 8:20
  • It's important to remember that PHP doesn't know anything about onclick events and vice versa; all you're doing is building some HTML, which as far as PHP is concerned is just text. So it doesn't make any difference to PHP whether the code is in an onclick element or a marquee tag. Commented Jun 1, 2018 at 8:22
  • I reopened (silly me), but I think you should still read this: Execute PHP function with onClick Commented Jun 1, 2018 at 8:23
  • Oh I see, I then just use AJAX I have tempered with it but this will be a new chalange for me. How silly of me that I did not know that php does not work on onclick, thanks! Commented Jun 1, 2018 at 8:32

2 Answers 2

1

The pseudo-variable $this is available when a method is called from within an object context. If your code is not part of class definition, you must create object first:

$obj = new Class();

Then use class methods with:

$obj->getAllMonths($dateMonth);.

You can read this about PHP classes.

Sign up to request clarification or add additional context in comments.

Comments

0

check this code. you are add '<?php echo date("Y",strtotime($date.' - 1 Month')); ?>' here single cotetion remove this.

 <a href="javascript:void(0);" onclick="getCalendar('calendar_div',<?php echo date("Y",strtotime($date.' - 1 Month')); ?>,<?php echo date("m",strtotime($date.' - 1 Month')); ?>);"><span class="glyphicon glyphicon-chevron-left"></span></a>

 <select name="month_dropdown" class="month_dropdown dropdown"><?php echo $this->getAllMonths($dateMonth); ?></select>

 <select name="year_dropdown" class="year_dropdown dropdown"><?php echo $this->getYearList($dateYear); ?></select>

 <a href="javascript:void(0);" onclick="getCalendar('calendar_div',<?php echo date("Y",strtotime($date.' + 1 Month')); ?>,<?php echo date("m",strtotime($date.' + 1 Month')); ?>);"><span class="glyphicon glyphicon-chevron-right"></span></a>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.