Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

AJAX refuses to work despite all efforts; "Error on Page"

I have been working for a long time on a simple calendar, with the idea being that you click on a day number, and you are presented with a textbox, you can edit what is in that textbox and save it to that calendar cell. I have not gotten very far because i can not get it to work at all, i had it working for a short time in IE, but now the catch(e) thing does not go through, so nothing happens, and i didnt change anything.

i have been working on it for over a month, and i have not gotte beyond this step because i cannot get this step to work. it is ridiculously frustrating

could somebody please look at my code and tell me what things i am doing wrong. i have never used javascript before, but despite a lot of the code being blatantly copied from w3schools tutorials, it refuses to work.

you can see the actual calendar at alex.jowigo.com/wikidar.php

this is the code for the main page

<html>
<head>
<title>
Room Booking Calendar
</title>
<style type="text/css">
table.cal{
width: 100%;
}
tr.day{
Height:200px;
vertical-align:text-top
}

</style>
<script src="calfunctions.js" >

</script>
</head>
<body>
<table class="cal" border="1">
<tr>
<td width="13%"> Sunday</td>
<td width="13%"> Monday</td>
<td width="13%"> Tuesday</td>
<td width="13%"> Wednesday</td>
<td width="13%"> Thursday</td>
<td width="13%"> Friday</td>
<td width="13%"> Saturday</td>
</tr>
<tr class="day">
<?php
$username = "jowigo1_alex";
$password = "m00";
$server = "supremecenter39.com";
mysql_connect($server,$username,$password);
mysql_select_db($username);
$month = "2";//$_POST["month"];
$year = "2007";//$_POST["year"];
$utime = mktime(1,1,1,$month,1,$year);
$weekday = date('w',$utime);
$weekday *= -1;
$monthdays = cal_days_in_month(CAL_GREGORIAN, $month, $year);
$sql = "SELECT * FROM wikidar WHERE year=" . $year . " and month=" . $month;
$result = mysql_query($sql);
if (mysql_num_rows($result) == 0)
{
for($i=1;$i<=$monthdays;$i++)
{
$sql = "INSERT INTO wikidar VALUES('',''," . $year . "," . $month . "," . $i . ")";
mysql_query($sql);
}
$sql = "SELECT * FROM 'wikidar' WHERE 'year'=" . $year . " 'month'=" . $month;
$result=mysql_query($sql);
}
for ($i=1;$weekday < $monthdays;$i++)
{
$weekday++;
echo "<td ";
if ($weekday > 0)
{
echo 'id="D' . $weekday . '">';
echo "<a href='javascript:LoadEdit(" . $year . "," . $month . "," . $weekday . ");' >" . $weekday . "</a>";
echo mysql_result($result,$weekday-1,'content');

}
else
{
echo ">";
}
echo "</td>";
if(is_int($i/7))
{
echo "</tr> <tr class='day'>";
}
}
mysql_close();
?>
</tr>
</table>
</body>
</html>

and this is the javascript, it did at one point, have semicolons at the end of every line which should, but they werent helping so i took them out

var xmlhttp
var dayn

function AjaxFunction(){
var ajaxrequest
try
{

ajaxrequest = new XMLHttpRequest()
}
catch(e)
{
try
{
ajaxrequest = new ActiveXObject("Msxml2.XMLHTTP")
}
catch(e)
{
try
{
ajaxrequest = new ActiveXObject("Microsoft.XMLHTTP")
}
catch(e)
{
// Something went wrong
alert("Your browser broke!")
//ajaxrequest = null;
}
}
}
return ajaxrequest
}

function StateChanged()
{
if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete")
{
document.getElementById["D" + dayn].innerHTML = xmlhttp.responseText
}
}


function LoadEdit(yr ,mnth, dy)
{
var xmlhttp = AjaxFunction()

if (xmlhttp == null)
{
alert("No Browser Support")
return
}

var urle = "editbox.php"
urle = urle + "?y=" + yr
urle = urle + "&m=" + mnth
urle = urle + "&d=" + dy
urle = urle + "&sid=" + Math.random()

xmlhttp.onreadystatechange = StateChanged

dayn = dy
xmlhttp.open("GET",url,true)
xmlhttp.send(null)

}

and editbox.php works fine

i would really appreciate any help on this
[5080 byte] By [notquitehere188] at [2007-11-11 10:27:09]