ragazzi sto lentamente entrando nel mondo di ajax (abbinato a PHP in questo frangente) qualcuno mi può testare questo codice che dovrebbe far comparire un calendario al volo
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Esempio 3_1</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="functions.js"></script>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="createtask" class="formclass"></div>
<div id="autocompletediv" class="autocomp"></div>
<div id="taskox" class="taskboxclass"></div>
<a href="javascript://" onclick="showHideCalendar()">
[img]images/plus.gif[/img]
</a>
My Calendar
</p>
<div id="calendar" style="width: 105px; text-align: left;"></div>
</body>
</html>
il file functions.js
var xmlhttp = false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMHttpRequest != 'undefined'){
xmlhttp = new XMLHttpRequest();
}
var showCalendar = true;
function showHideCalendar() {
var objID = "calendar";
if (showCalendar == true){
document.getElementById("opencloseimg").src = "images/mins.gif";
var serverPage = "calendar.php";
showCalendar = false;
var obj = document.getElementById(objID);
xmlhttp.open("GET", serverPage);
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
obj.innerHTML = xmlhttp.response.Text;
}
}
xmlhttp.send(null);
} else {
document.getElementById("opencloseimg").src = "images/plus.gif";
showCalendar = true;
document.getElementById(objID).innerHTML = "";
}
}
e infine il file calendar.php
<?php
if((!$_GET['month']) && (!$_GET['year'])) {
$month = date("n");
$year = date("Y");
} else {
$month = $_GET['month'];
$year = $_GET['year'];
}
$timestamp = mktime(0, 0, 0, $month, 1, $year);
$monthname = date("F", $timestamp);
?>
<table style="width: 105px; border-collapse: collapse;" border="1" cellpadding="3" cellspacing="0" bordercolor="#000000">
<tr style="background: #FFBC37;">
<td colspan="7" style="text-align: center;" onMouseOver="this.style.background='#FECE6E'" onMouseOut="this.style.background='#FFBC37'">
<span style="font-weight: bold;"><?php echo $monthname . " " . $year; ?></span>
</td>
</tr>
<tr style="background: #FFBC37;">
<td style="text-align: center; width: 15px;" onMouseOver="this.style.background='#FECE6E'" onMouseOut="this.style.background='#FFBC37'">
<span style="font-weight: bold;">Su</span>
</td>
<td style="text-align: center; width: 15px;" onMouseOver="this.style.background='#FECE6E'" onMouseOut="this.style.background='#FFBC37'">
<span style="font-weight: bold;">M</span>
</td>
<td style="text-align: center; width: 15px;" onMouseOver="this.style.background='#FECE6E'" onMouseOut="this.style.background='#FFBC37'">
<span style="font-weight: bold;">Tu</span>
</td>
<td style="text-align: center; width: 15px;" onMouseOver="this.style.background='#FECE6E'" onMouseOut="this.style.background='#FFBC37'">
<span style="font-weight: bold;">W</span>
</td>
<td style="text-align: center; width: 15px;" onMouseOver="this.style.background='#FECE6E'" onMouseOut="this.style.background='#FFBC37'">
<span style="font-weight: bold;">Th</span>
</td>
<td style="text-align: center; width: 15px;" onMouseOver="this.style.background='#FECE6E'" onMouseOut="this.style.background='#FFBC37'">
<span style="font-weight: bold;">F</span>
</td>
<td style="text-align: center; width: 15px;" onMouseOver="this.style.background='#FECE6E'" onMouseOut="this.style.background='#FFBC37'">
<span style="font-weight: bold;">Sa</span>
</td>
</tr>
<?php
$monthstart = date("w", $timestamp);
$lastday = date("d", mktime (0, 0, 0, $month + 1, 0, $year));
$startdate = -$monthstart;
$munrows = ceil (((date("t", mktime(0, 0, 0, $month + 1, 0, $year)) + $monthstart) / 7));
for ($k = 1; $k <= $numrows; $k++) {
?>
<tr><?php
for ($i = 0; $i < 7; $i++){
$startdate++;
if (($startdate <= 0) || ($startdate > $lastday)){
?><td style="background: #FFFFFF;"></td>
<?php
} else {
if ($startdate == date("j") && $month == date("n") && $year == date("Y")) {
?>
<td style="text-align: center; background: #FFBC37;" onMouseOver="this.style.background='#FECE6E'" onMouseOut="this.style.background='#FFBC37'">
<?php echo date("j"); ?>
</td>
<?php
} else {
?>
<td style="text-align: center; background: #A2BAFA;" onMouseOver="this.style.background='#CAD7F9'" onMouseOut="this.style.background='#A2BAFA'">
<?php echo $startdate; ?>
</td>
<?php
}
}
}
?></tr><?php
}
?>
</table>

Rispondi quotando