I am making an event calendar.I want to echo a function in php using button.
My actual code:
Calendar.php
<?php include_once('functions.php'); ?>
<?php echo getCalender(); ?>
functions.php
<?php
if(isset($_POST['func']) && !empty($_POST['func'])){
switch($_POST['func']){
case 'getCalender':
getCalender($_POST['year'],$_POST['month']);
break;
case 'getEvents':
getEvents($_POST['date']);
break;
default:
break;
}
}
//Get calendar full HTML
function getCalender($year = '',$month = '')
{
$dateYear = ($year != '')?$year:date("Y");
$dateMonth = ($month != '')?$month:date("m");
$date = $dateYear.'-'.$dateMonth.'-01';
$currentMonthFirstDay = date("N",strtotime($date));
$totalDaysOfMonth = cal_days_in_month(CAL_GREGORIAN,$dateMonth,$dateYear);
$totalDaysOfMonthDisplay = ($currentMonthFirstDay == 7)?($totalDaysOfMonth):($totalDaysOfMonth + $currentMonthFirstDay);
$boxDisplay = ($totalDaysOfMonthDisplay <= 35)?35:42;
?>
<div id="calender_section">
//
}
<script type="text/javascript">
function getCalendar(target_div,year,month){
$.ajax({
type:'POST',
url:'functions.php',
data:'func=getCalender&year='+year+'&month='+month,
success:function(html){
$('#'+target_div).html(html);
}
});
}
function getEvents(date){
$.ajax({
type:'POST',
url:'functions.php',
data:'func=getEvents&date='+date,
success:function(html){
$('#event_list').html(html);
$('#event_add').slideUp('slow');
$('#event_list').slideDown('slow');
}
});
}
Now I want to use button to call the getcalendar function. I've tried this:
Calendar.php
<form class="" action="" method="post">
<input type="button" value="Dhaka" onclick="<?php echo getCalender(); ?>"/>
</form>
Now this is not waitiing for button click. When I refresh the page it is showing the calendat even if i didn't click the button. How can I solve this?