Ajax calendar -- help  | Familiar Sight | | Join Date: Oct 2006 Location: Florida
Posts: 204
| |
I downloaded this calendar off the web and am trying have it show twice, once as calendar.php and the second time as calendar1.php
I need the visitor to be able to select a beginning date and an ending date. Here is the primary page that I have -
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'>
-
<html>
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
-
<title>Your Title</title>
-
<link rel="stylesheet" type="text/css" href="calendar_style.css">
-
<script type="text/javascript">
-
var req;
-
-
function navigate(month,year) {
-
var url = "calendar.php?month="+month+"&year="+year;
-
if(window.XMLHttpRequest) {
-
req = new XMLHttpRequest();
-
} else if(window.ActiveXObject) {
-
req = new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
req.open("GET", url, true);
-
req.onreadystatechange = callback;
-
req.send(null);
-
}
-
-
function callback() {
-
if(req.readyState == 4) {
-
if(req.status == 200) {
-
response = req.responseText;
-
document.getElementById("calendar").innerHTML = response;
-
} else {
-
alert("There was a problem retrieving the data:\n" + req.statusText);
-
}
-
}
-
}
-
</script>
-
<script type="text/javascript">
-
var req;
-
-
function navigate1(month,year) {
-
var url = "calendar1.php?month="+month+"&year="+year;
-
if(window.XMLHttpRequest) {
-
req = new XMLHttpRequest();
-
} else if(window.ActiveXObject) {
-
req = new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
req.open("GET", url, true);
-
req.onreadystatechange = callback;
-
req.send(null);
-
}
-
-
function callback1() {
-
if(req.readyState == 4) {
-
if(req.status == 200) {
-
response = req.responseText;
-
document.getElementById("calendar1").innerHTML = response;
-
} else {
-
alert("There was a problem retrieving the data:\n" + req.statusText);
-
}
-
}
-
}
-
</script>
-
<script type="text/javascript">
-
function init()
-
-
{
-
navigate("","");
-
navigate1("","");
-
}
-
//-->
-
</script>
-
</head>
-
<body onLoad="init()">
-
<div id="calendar" style="margin-top: 20px;margin-bottom: 20px"></div>
-
-
</body>
-
</html>
-
And here is the AJAX Calendar -
<?
-
-
$output = '';
-
-
if($_GET[month] == '' && $$_GET[year] == '') {
-
$time = time();
-
$month = date('n',$time);
-
$year = date('Y',$time);
-
}
-
-
$date = getdate(mktime(0,0,0,$month,1,$year));
-
$today = getdate();
-
$hours = $today[hours];
-
$mins = $today[minutes];
-
$secs = $today[seconds];
-
-
if(strlen($hours)<2) $hours="0".$hours;
-
if(strlen($mins)<2) $mins="0".$mins;
-
if(strlen($secs)<2) $secs="0".$secs;
-
-
$days=date("t",mktime(0,0,0,$month,1,$year));
-
$start = $date[wday]+1;
-
$name = $date[month];
-
$year2 = $date[year];
-
$offset = $days + $start - 1;
-
-
if($month==12) {
-
$next=1;
-
$nexty=$year + 1;
-
} else {
-
$next=$month + 1;
-
$nexty=$year;
-
}
-
-
if($month==1) {
-
$prev=12;
-
$prevy=$year - 1;
-
} else {
-
$prev=$month - 1;
-
$prevy=$year;
-
}
-
-
if($offset <= 28) $weeks=28;
-
elseif($offset > 35) $weeks = 42;
-
else $weeks = 35;
-
-
$output = "<table class='daytable' cellpadding='3' cellspacing='1' align='center'>
-
<tr>
-
<td colspan='7'>
-
<table border='0' width='100%'>
-
<tr>
-
<td valign='middle'>
-
<a href='javascript:navigate($prev,$prevy)'><img src='left.gif' border='0'></a><a href='javascript:navigate(\"\",\"\")'><img src='center.gif' hspace='3' border='0'></a><a href='javascript:navigate($next,$nexty)'><img src='right.gif' border='0'></a>
-
</td>
-
<td align='right'>
-
<div id='heading'>$name $year2</div>
-
</td>
-
</tr>
-
</table>
-
</td>
-
</tr>
-
<tr>
-
<td class='dayhead'>Sun</td>
-
<td class='dayhead'>Mon</td>
-
<td class='dayhead'>Tue</td>
-
<td class='dayhead'>Wed</td>
-
<td class='dayhead'>Thu</td>
-
<td class='dayhead'>Fri</td>
-
<td class='dayhead'>Sat</td>
-
</tr>";
-
-
$col=1;
-
$cur=1;
-
$next=0;
-
-
for($i=1;$i<=$weeks;$i++) {
-
if($next==3) $next=0;
-
if($col==1) $output.="<tr class='dayrow'>";
-
-
$output.="<td valign='top' class='days' onMouseOver=\"this.style.backgroundColor='#EEEEEE'\" onMouseOut=\"this.style.backgroundColor='#FFFFFF'\">";
-
-
if($i <= ($days+($start-1)) && $i >= $start) {
-
$output.="<div";
-
-
if(($cur==$today[mday]) && ($name==$today[month])) $output.=" style='color:#FF0000'";
-
$output.="><b>$cur</b>";
-
-
$output.="</div></td>";
-
$cur++;
-
$col++;
-
} else {
-
$output.=" </td>";
-
$col++;
-
}
-
-
if($col==8) {
-
$output.="</tr>";
-
$col=1;
-
}
-
}
-
-
$output.="</table>";
-
-
echo $output;
-
-
?>
-
All I did is name calendar.php to calendar1.php and copied and changed the function.
somehow or another I am lost in what I did and appreciate any help to get both calendars to display at the same time and they will both have different outputs.
An arrival time and a departure time.
Thanks in Advance
|  | Familiar Sight | | Join Date: Oct 2006 Location: Florida
Posts: 204
| | | re: Ajax calendar -- help |  | Expert | | Join Date: Dec 2006 Location: Pittsburgh
Posts: 171
| | | re: Ajax calendar -- help Using more than 1 XMLRequest is a drag. To be compatible all around you need to do only
|  | Expert | | Join Date: Dec 2006 Location: Pittsburgh
Posts: 171
| | | re: Ajax calendar -- help Using more than 1 XMLRequest is a drag. To be compatible all around you need to do only 1 request per request object then destroy the old one and make a new. It is stupid, I know, but that's where ajax is at. So it looks like you have only 1 request object ("var req"); That can be the source of your problem. You'll need req1 and req2. Also, be sure you call the constructor every time you're going to send a new request. Good luck!
|  | Familiar Sight | | Join Date: Oct 2006 Location: Florida
Posts: 204
| | | re: Ajax calendar -- help
I changed the var req; to var req1; and still no changes in the functionality. -
<script type='text/javascript'>
-
var req;
-
-
function navigate(month,year) {
-
var url = "calendar.php?month="+month+"&year="+year;
-
if(window.XMLHttpRequest) {
-
req = new XMLHttpRequest();
-
} else if(window.ActiveXObject) {
-
req = new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
req.open("GET", url, true);
-
req.onreadystatechange = callback;
-
req.send(null);
-
}
-
-
function callback() {
-
if(req.readyState == 4) {
-
if(req.status == 200) {
-
response = req.responseText;
-
document.getElementById("calendar").innerHTML = response;
-
} else {
-
alert("There was a problem retrieving the data:\n" + req.statusText);
-
}
-
}
-
}
-
</script>
-
<script type='text/javascript'>
-
var req1;
-
-
function navigate1(month,year) {
-
var url = "calendar1.php?month="+month+"&year="+year;
-
if(window.XMLHttpRequest) {
-
req1 = new XMLHttpRequest();
-
} else if(window.ActiveXObject) {
-
req 1= new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
req1.open("GET", url, true);
-
req1.onreadystatechange = callback;
-
req1.send(null);
-
}
-
-
function callback1() {
-
if(req1.readyState == 4) {
-
if(req1.status == 200) {
-
response = req1.responseText;
-
document.getElementById("calendar1").innerHTML = response;
-
} else {
-
alert("There was a problem retrieving the data:\n" + req1.statusText);
-
}
-
}
-
}
-
</script>
-
<script type="text/javascript">
-
function init()
-
-
{
-
navigate("","");
-
navigate1("","");
-
}
-
//-->
-
</script>
-
</head>
-
<body onLoad="init()">
-
It isn't even opening a second instance of the calendar. That is also one of the problems
|  | Expert | | Join Date: Dec 2006 Location: Pittsburgh
Posts: 171
| | | re: Ajax calendar -- help Quote:
Originally Posted by cassbiz I changed the var req; to var req1; and still no changes in the functionality. -
<script type='text/javascript'>
-
var req;
-
-
function navigate(month,year) {
-
var url = "calendar.php?month="+month+"&year="+year;
-
if(window.XMLHttpRequest) {
-
req = new XMLHttpRequest();
-
} else if(window.ActiveXObject) {
-
req = new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
req.open("GET", url, true);
-
req.onreadystatechange = callback;
-
req.send(null);
-
}
-
-
function callback() {
-
if(req.readyState == 4) {
-
if(req.status == 200) {
-
response = req.responseText;
-
document.getElementById("calendar").innerHTML = response;
-
} else {
-
alert("There was a problem retrieving the data:\n" + req.statusText);
-
}
-
}
-
}
-
</script>
-
<script type='text/javascript'>
-
var req1;
-
-
function navigate1(month,year) {
-
var url = "calendar1.php?month="+month+"&year="+year;
-
if(window.XMLHttpRequest) {
-
req1 = new XMLHttpRequest();
-
} else if(window.ActiveXObject) {
-
req 1= new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
req1.open("GET", url, true);
-
req1.onreadystatechange = callback;
-
req1.send(null);
-
}
-
-
function callback1() {
-
if(req1.readyState == 4) {
-
if(req1.status == 200) {
-
response = req1.responseText;
-
document.getElementById("calendar1").innerHTML = response;
-
} else {
-
alert("There was a problem retrieving the data:\n" + req1.statusText);
-
}
-
}
-
}
-
</script>
-
<script type="text/javascript">
-
function init()
-
-
{
-
navigate("","");
-
navigate1("","");
-
}
-
//-->
-
</script>
-
</head>
-
<body onLoad="init()">
-
It isn't even opening a second instance of the calendar. That is also one of the problems I always end up doing something like this to be sure my ajax is wired right: -
function callback1() {
-
if(req1.readyState == 4) {
-
alert("got a response");
-
if(req1.status == 200) {
-
response = req1.responseText;
-
alert ("response was: " + response.Text);
-
document.getElementById("calendar1").innerHTML = response;
-
} else {
-
alert("There was a problem retrieving the data:\n" + req1.statusText);
-
}
-
}
-
}
-
See if you are getting those alert messages back properly. I don't have access to php right now or I'd fire it up and see what was going on first hand.
|  | Moderator | | Join Date: Jul 2006 Location: The Netherlands
Posts: 4,139
| | | re: Ajax calendar -- help
In your first post you had the following code (part of it)[php]function callback1() {
if(req.readyState == 4) {
if(req.status == 200) {
response = req.responseText;
document.getElementById("calendar1").innerHTML = response;
} else {
alert("There was a problem retrieving the data:\n" + req.statusText);
}
}
}
</script>
<script type="text/javascript">
function init()
{
navigate("","");
navigate1("","");
}
//-->
</script>
</head>
<body onLoad="init()">
<div id="calendar" style="margin-top: 20px;margin-bottom: 20px"></div>
</body>
</html>[/php]
In your JS statement you address document.getElementById("calendar1").
In your HTML you have defined the div as <div id="calendar" style="margin-top: 20px;margin-bottom: 20px"></div>\
Looks like the two id's are not identical.
Ronald :cool:
|  | Familiar Sight | | Join Date: Oct 2006 Location: Florida
Posts: 204
| | | re: Ajax calendar -- help
OK, here is what I have going.
b1randon, I put in the 'alert("response was: " + response.Text);' and am receiving the message that it is 'undefined'.
Ronald, I changed the div id to include both calendar and calendar1
Am I barking up the wrong tree trying to go this route? Or is there something blatant that I am missing?
The page is located at here |  | Moderator | | Join Date: Jul 2006 Location: The Netherlands
Posts: 4,139
| | | re: Ajax calendar -- help
What is this doing?[html]I put in the 'alert("response was: " + response.Text);'[/html]. If the response data was sent back to JS as plain text, there is no response.Text, just response. So your alert should be[html]alert("response was: " + response);[/html]
Ronald :cool:
|  | Familiar Sight | | Join Date: Oct 2006 Location: Florida
Posts: 204
| | | re: Ajax calendar -- help
Ronald, I followed the example from b1randon in regards to the response.
I did get it figured out (at least the javascript/AJAX) part. There were two errors. In the function navigate1 it was calling callback() not callback1() and then I changed the body OnLoad from init() to navigate("","");navigate1("","") and dropped the function init() alltogether.
Thank you again. The little tips led me in the right direction. This is a great forum!
:)
Here is the correct code in the event that someone would like to use it in the future.
ajax_calendar.php -
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'>
-
<html>
-
<head>
-
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
-
<title>Your Title</title>
-
<link rel='stylesheet' type='text/css' href='calendar_style.css'>
-
<script type='text/javascript'>
-
var req;
-
-
function navigate(month,year) {
-
var url = "calendar.php?month="+month+"&year="+year;
-
if(window.XMLHttpRequest) {
-
req = new XMLHttpRequest();
-
} else if(window.ActiveXObject) {
-
req = new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
req.open("GET", url, true);
-
req.onreadystatechange = callback;
-
req.send(null);
-
}
-
-
function callback() {
-
if(req.readyState == 4) {
-
if(req.status == 200) {
-
response = req.responseText;
-
document.getElementById("calendar").innerHTML = response;
-
} else {
-
alert("There was a problem retrieving the data:\n" + req.statusText);
-
}
-
}
-
}
-
</script>
-
<script type='text/javascript'>
-
var req1;
-
-
function navigate1(month,year) {
-
var url = "calendar1.php?month="+month+"&year="+year;
-
if(window.XMLHttpRequest) {
-
req1 = new XMLHttpRequest();
-
} else if(window.ActiveXObject) {
-
req1 = new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
req1.open("GET", url, true);
-
req1.onreadystatechange = callback1;
-
req1.send(null);
-
}
-
-
function callback1() {
-
if(req1.readyState == 4) {
-
if(req1.status == 200) {
-
response = req1.responseText;
-
document.getElementById("calendar1").innerHTML = response;
-
} else {
-
alert("There was a problem retrieving the data:\n" + req1.statusText);
-
}
-
}
-
}
-
</script>
-
</head>
-
<body onLoad='navigate("","");navigate1("","")'>
-
<div id='calendar' style='margin-top: 20px;margin-bottom: 20px'></div>
-
<div id='calendar1' style='margin-top: 100px;margin-bottom: 20px'></div>
-
</body>
-
</html>
-
calendar.php -
<?
-
-
$output = '';
-
-
if($_GET[month] == '' && $$_GET[year] == '') {
-
$time = time();
-
$month = date('n',$time);
-
$year = date('Y',$time);
-
}
-
-
$date = getdate(mktime(0,0,0,$month,1,$year));
-
$today = getdate();
-
$hours = $today[hours];
-
$mins = $today[minutes];
-
$secs = $today[seconds];
-
-
if(strlen($hours)<2) $hours="0".$hours;
-
if(strlen($mins)<2) $mins="0".$mins;
-
if(strlen($secs)<2) $secs="0".$secs;
-
-
$days=date("t",mktime(0,0,0,$month,1,$year));
-
$start = $date[wday]+1;
-
$name = $date[month];
-
$year2 = $date[year];
-
$offset = $days + $start - 1;
-
-
if($month==12) {
-
$next=1;
-
$nexty=$year + 1;
-
} else {
-
$next=$month + 1;
-
$nexty=$year;
-
}
-
-
if($month==1) {
-
$prev=12;
-
$prevy=$year - 1;
-
} else {
-
$prev=$month - 1;
-
$prevy=$year;
-
}
-
-
if($offset <= 28) $weeks=28;
-
elseif($offset > 35) $weeks = 42;
-
else $weeks = 35;
-
-
$output = "<table class='daytable' cellpadding='3' cellspacing='1' align='center'>
-
<tr>
-
<td colspan='7'>
-
<table border='0' width='100%'>
-
<tr>
-
<td valign='middle'>
-
<a href='javascript:navigate($prev,$prevy)'><img src='left.gif' border='0'></a><a href='javascript:navigate(\"\",\"\")'><img src='center.gif' hspace='3' border='0'></a><a href='javascript:navigate($next,$nexty)'><img src='right.gif' border='0'></a>
-
</td>
-
<td align='right'>
-
<div id='heading'>$name $year2</div>
-
</td>
-
</tr>
-
</table>
-
</td>
-
</tr>
-
<tr>
-
<td class='dayhead'>Sun</td>
-
<td class='dayhead'>Mon</td>
-
<td class='dayhead'>Tue</td>
-
<td class='dayhead'>Wed</td>
-
<td class='dayhead'>Thu</td>
-
<td class='dayhead'>Fri</td>
-
<td class='dayhead'>Sat</td>
-
</tr>";
-
-
$col=1;
-
$cur=1;
-
$next=0;
-
-
for($i=1;$i<=$weeks;$i++) {
-
if($next==3) $next=0;
-
if($col==1) $output.="<tr class='dayrow'>";
-
-
$output.="<td valign='top' class='days' onMouseOver=\"this.style.backgroundColor='#EEEEEE'\" onMouseOut=\"this.style.backgroundColor='#FFFFFF'\">";
-
-
if($i <= ($days+($start-1)) && $i >= $start) {
-
$output.="<div";
-
-
if(($cur==$today[mday]) && ($name==$today[month])) $output.=" style='color:#FF0000'";
-
$output.="><b>$cur</b>";
-
-
$output.="</div></td>";
-
$cur++;
-
$col++;
-
} else {
-
$output.=" </td>";
-
$col++;
-
}
-
-
if($col==8) {
-
$output.="</tr>";
-
$col=1;
-
}
-
}
-
-
$output.="</table>";
-
-
echo $output;
-
-
?>
-
calendar1.php -
<?
-
-
$output = '';
-
-
if($_GET[month] == '' && $$_GET[year] == '') {
-
$time = time();
-
$month = date('n',$time);
-
$year = date('Y',$time);
-
}
-
-
$date = getdate(mktime(0,0,0,$month,1,$year));
-
$today = getdate();
-
$hours = $today[hours];
-
$mins = $today[minutes];
-
$secs = $today[seconds];
-
-
if(strlen($hours)<2) $hours="0".$hours;
-
if(strlen($mins)<2) $mins="0".$mins;
-
if(strlen($secs)<2) $secs="0".$secs;
-
-
$days=date("t",mktime(0,0,0,$month,1,$year));
-
$start = $date[wday]+1;
-
$name = $date[month];
-
$year2 = $date[year];
-
$offset = $days + $start - 1;
-
-
if($month==12) {
-
$next=1;
-
$nexty=$year + 1;
-
} else {
-
$next=$month + 1;
-
$nexty=$year;
-
}
-
-
if($month==1) {
-
$prev=12;
-
$prevy=$year - 1;
-
} else {
-
$prev=$month - 1;
-
$prevy=$year;
-
}
-
-
if($offset <= 28) $weeks=28;
-
elseif($offset > 35) $weeks = 42;
-
else $weeks = 35;
-
-
$output = "<table class='daytable' cellpadding='3' cellspacing='1' align='center'>
-
<tr>
-
<td colspan='7'>
-
<table border='0' width='100%'>
-
<tr>
-
<td valign='middle'>
-
<a href='javascript:navigate1($prev,$prevy)'><img src='left.gif' border='0'></a><a href='javascript:navigate1(\"\",\"\")'><img src='center.gif' hspace='3' border='0'></a><a href='javascript:navigate1($next,$nexty)'><img src='right.gif' border='0'></a>
-
</td>
-
<td align='right'>
-
<div id='heading'>c1 $name $year2</div>
-
</td>
-
</tr>
-
</table>
-
</td>
-
</tr>
-
<tr>
-
<td class='dayhead'>Sun</td>
-
<td class='dayhead'>Mon</td>
-
<td class='dayhead'>Tue</td>
-
<td class='dayhead'>Wed</td>
-
<td class='dayhead'>Thu</td>
-
<td class='dayhead'>Fri</td>
-
<td class='dayhead'>Sat</td>
-
</tr>";
-
-
$col=1;
-
$cur=1;
-
$next=0;
-
-
for($i=1;$i<=$weeks;$i++) {
-
if($next==3) $next=0;
-
if($col==1) $output.="<tr class='dayrow'>";
-
-
$output.="<td valign='top' class='days' onMouseOver=\"this.style.backgroundColor='#EEEEEE'\" onMouseOut=\"this.style.backgroundColor='#FFFFFF'\">";
-
-
if($i <= ($days+($start-1)) && $i >= $start) {
-
$output.="<div";
-
-
if(($cur==$today[mday]) && ($name==$today[month])) $output.=" style='color:#FF0000'";
-
$output.="><b>$cur</b>";
-
-
$output.="</div></td>";
-
$cur++;
-
$col++;
-
} else {
-
$output.=" </td>";
-
$col++;
-
}
-
-
if($col==8) {
-
$output.="</tr>";
-
$col=1;
-
}
-
}
-
-
$output.="</table>";
-
-
echo $output;
-
-
?>
-
|  | Expert | | Join Date: Dec 2006 Location: Pittsburgh
Posts: 171
| | | re: Ajax calendar -- help Quote:
Originally Posted by cassbiz Ronald, I followed the example from b1randon in regards to the response.
I did get it figured out (at least the javascript/AJAX) part. There were two errors. In the function navigate1 it was calling callback() not callback1() and then I changed the body OnLoad from init() to navigate("","");navigate1("","") and dropped the function init() alltogether.
Thank you again. The little tips led me in the right direction. This is a great forum!
:)
Here is the correct code in the event that someone would like to use it in the future.
ajax_calendar.php -
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'>
-
<html>
-
<head>
-
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
-
<title>Your Title</title>
-
<link rel='stylesheet' type='text/css' href='calendar_style.css'>
-
<script type='text/javascript'>
-
var req;
-
-
function navigate(month,year) {
-
var url = "calendar.php?month="+month+"&year="+year;
-
if(window.XMLHttpRequest) {
-
req = new XMLHttpRequest();
-
} else if(window.ActiveXObject) {
-
req = new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
req.open("GET", url, true);
-
req.onreadystatechange = callback;
-
req.send(null);
-
}
-
-
function callback() {
-
if(req.readyState == 4) {
-
if(req.status == 200) {
-
response = req.responseText;
-
document.getElementById("calendar").innerHTML = response;
-
} else {
-
alert("There was a problem retrieving the data:\n" + req.statusText);
-
}
-
}
-
}
-
</script>
-
<script type='text/javascript'>
-
var req1;
-
-
function navigate1(month,year) {
-
var url = "calendar1.php?month="+month+"&year="+year;
-
if(window.XMLHttpRequest) {
-
req1 = new XMLHttpRequest();
-
} else if(window.ActiveXObject) {
-
req1 = new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
req1.open("GET", url, true);
-
req1.onreadystatechange = callback1;
-
req1.send(null);
-
}
-
-
function callback1() {
-
if(req1.readyState == 4) {
-
if(req1.status == 200) {
-
response = req1.responseText;
-
document.getElementById("calendar1").innerHTML = response;
-
} else {
-
alert("There was a problem retrieving the data:\n" + req1.statusText);
-
}
-
}
-
}
-
</script>
-
</head>
-
<body onLoad='navigate("","");navigate1("","")'>
-
<div id='calendar' style='margin-top: 20px;margin-bottom: 20px'></div>
-
<div id='calendar1' style='margin-top: 100px;margin-bottom: 20px'></div>
-
</body>
-
</html>
-
calendar.php -
<?
-
-
$output = '';
-
-
if($_GET[month] == '' && $$_GET[year] == '') {
-
$time = time();
-
$month = date('n',$time);
-
$year = date('Y',$time);
-
}
-
-
$date = getdate(mktime(0,0,0,$month,1,$year));
-
$today = getdate();
-
$hours = $today[hours];
-
$mins = $today[minutes];
-
$secs = $today[seconds];
-
-
if(strlen($hours)<2) $hours="0".$hours;
-
if(strlen($mins)<2) $mins="0".$mins;
-
if(strlen($secs)<2) $secs="0".$secs;
-
-
$days=date("t",mktime(0,0,0,$month,1,$year));
-
$start = $date[wday]+1;
-
$name = $date[month];
-
$year2 = $date[year];
-
$offset = $days + $start - 1;
-
-
if($month==12) {
-
$next=1;
-
$nexty=$year + 1;
-
} else {
-
$next=$month + 1;
-
$nexty=$year;
-
}
-
-
if($month==1) {
-
$prev=12;
-
$prevy=$year - 1;
-
} else {
-
$prev=$month - 1;
-
$prevy=$year;
-
}
-
-
if($offset <= 28) $weeks=28;
-
elseif($offset > 35) $weeks = 42;
-
else $weeks = 35;
-
-
$output = "<table class='daytable' cellpadding='3' cellspacing='1' align='center'>
-
<tr>
-
<td colspan='7'>
-
<table border='0' width='100%'>
-
<tr>
-
<td valign='middle'>
-
<a href='javascript:navigate($prev,$prevy)'><img src='left.gif' border='0'></a><a href='javascript:navigate(\"\",\"\")'><img src='center.gif' hspace='3' border='0'></a><a href='javascript:navigate($next,$nexty)'><img src='right.gif' border='0'></a>
-
</td>
-
<td align='right'>
-
<div id='heading'>$name $year2</div>
-
</td>
-
</tr>
-
</table>
-
</td>
-
</tr>
-
<tr>
-
<td class='dayhead'>Sun</td>
-
<td class='dayhead'>Mon</td>
-
<td class='dayhead'>Tue</td>
-
<td class='dayhead'>Wed</td>
-
<td class='dayhead'>Thu</td>
-
<td class='dayhead'>Fri</td>
-
<td class='dayhead'>Sat</td>
-
</tr>";
-
-
$col=1;
-
$cur=1;
-
$next=0;
-
-
for($i=1;$i<=$weeks;$i++) {
-
if($next==3) $next=0;
-
if($col==1) $output.="<tr class='dayrow'>";
-
-
$output.="<td valign='top' class='days' onMouseOver=\"this.style.backgroundColor='#EEEEEE'\" onMouseOut=\"this.style.backgroundColor='#FFFFFF'\">";
-
-
if($i <= ($days+($start-1)) && $i >= $start) {
-
$output.="<div";
-
-
if(($cur==$today[mday]) && ($name==$today[month])) $output.=" style='color:#FF0000'";
-
$output.="><b>$cur</b>";
-
-
$output.="</div></td>";
-
$cur++;
-
$col++;
-
} else {
-
$output.=" </td>";
-
$col++;
-
}
-
-
if($col==8) {
-
$output.="</tr>";
-
$col=1;
-
}
-
}
-
-
$output.="</table>";
-
-
echo $output;
-
-
?>
-
calendar1.php -
<?
-
-
$output = '';
-
-
if($_GET[month] == '' && $$_GET[year] == '') {
-
$time = time();
-
$month = date('n',$time);
-
$year = date('Y',$time);
-
}
-
-
$date = getdate(mktime(0,0,0,$month,1,$year));
-
$today = getdate();
-
$hours = $today[hours];
-
$mins = $today[minutes];
-
$secs = $today[seconds];
-
-
if(strlen($hours)<2) $hours="0".$hours;
-
if(strlen($mins)<2) $mins="0".$mins;
-
if(strlen($secs)<2) $secs="0".$secs;
-
-
$days=date("t",mktime(0,0,0,$month,1,$year));
-
$start = $date[wday]+1;
-
$name = $date[month];
-
$year2 = $date[year];
-
$offset = $days + $start - 1;
-
-
if($month==12) {
-
$next=1;
-
$nexty=$year + 1;
-
} else {
-
$next=$month + 1;
-
$nexty=$year;
-
}
-
-
if($month==1) {
-
$prev=12;
-
$prevy=$year - 1;
-
} else {
-
$prev=$month - 1;
-
$prevy=$year;
-
}
-
-
if($offset <= 28) $weeks=28;
-
elseif($offset > 35) $weeks = 42;
-
else $weeks = 35;
-
-
$output = "<table class='daytable' cellpadding='3' cellspacing='1' align='center'>
-
<tr>
-
<td colspan='7'>
-
<table border='0' width='100%'>
-
<tr>
-
<td valign='middle'>
-
<a href='javascript:navigate1($prev,$prevy)'><img src='left.gif' border='0'></a><a href='javascript:navigate1(\"\",\"\")'><img src='center.gif' hspace='3' border='0'></a><a href='javascript:navigate1($next,$nexty)'><img src='right.gif' border='0'></a>
-
</td>
-
<td align='right'>
-
<div id='heading'>c1 $name $year2</div>
-
</td>
-
</tr>
-
</table>
-
</td>
-
</tr>
-
<tr>
-
<td class='dayhead'>Sun</td>
-
<td class='dayhead'>Mon</td>
-
<td class='dayhead'>Tue</td>
-
<td class='dayhead'>Wed</td>
-
<td class='dayhead'>Thu</td>
-
<td class='dayhead'>Fri</td>
-
<td class='dayhead'>Sat</td>
-
</tr>";
-
-
$col=1;
-
$cur=1;
-
$next=0;
-
-
for($i=1;$i<=$weeks;$i++) {
-
if($next==3) $next=0;
-
if($col==1) $output.="<tr class='dayrow'>";
-
-
$output.="<td valign='top' class='days' onMouseOver=\"this.style.backgroundColor='#EEEEEE'\" onMouseOut=\"this.style.backgroundColor='#FFFFFF'\">";
-
-
if($i <= ($days+($start-1)) && $i >= $start) {
-
$output.="<div";
-
-
if(($cur==$today[mday]) && ($name==$today[month])) $output.=" style='color:#FF0000'";
-
$output.="><b>$cur</b>";
-
-
$output.="</div></td>";
-
$cur++;
-
$col++;
-
} else {
-
$output.=" </td>";
-
$col++;
-
}
-
-
if($col==8) {
-
$output.="</tr>";
-
$col=1;
-
}
-
}
-
-
$output.="</table>";
-
-
echo $output;
-
-
?>
-
Glad that I could be of service. Thanks for posting the solution. Congrats too, multiple XMLRequest objects can be tricky.
|  | Familiar Sight | | Join Date: Oct 2006 Location: Florida
Posts: 204
| | | re: Ajax calendar -- help
No Problem,
Now comes the fun part of querying the DB and setting up the output characteristics.
| | Newbie | | Join Date: Feb 2007
Posts: 1
| | | re: Ajax calendar -- help
Hey, I have question. It seems that navigation in header is not working properly (month) . When I click for March 2007, from February 2007 it shows December 1999..Where is the problem? Thnx
|  | Similar JavaScript / Ajax / DHTML bytes | | | Forums
Visit our community forums for general discussions and latest on Bytes
/bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 229,136 network members.
|