I’m getting an odd error, and I can’t quite figure out why.
[URL=”http://localhost/motorpro/admin/error.php”]Site Is Here
I’ve got a page that will update a database, either changing the number of participants in a class or adding another class entirely.
Both versions use the same XMLHttpRequest function to call another PHP file to update or add the information to the MySQL database.
However, while the form which updates the number of participants in a class works fine, the one to add a class does not, with Firefox Error Console telling me “xmlhttp is undefined”.
[CODE]
var xmlhttp;
function load_external(url,run_name)
{
xmlhttp=null;
if (window.XMLHttpRequest)
{// code for all new browsers
xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE5 and IE6
xmlhttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
if (xmlhttp!=null)
{
xmlhttp.onreadystatechange=run_name;
xmlhttp.open(“GET”,url,true);
xmlhttp.send(null);
}
else
{
alert(“Your browser does not support this function.”);
}
}
function updateCurrentClasses(date,spaces) {
infoURL = “demo.php”;
load_external(infoURL,update_classes);
}
function update_classes() {
if (xmlhttp.readyState==4)
{// 4 = “loaded”
if (xmlhttp.status==200)
{// 200 = OK
alert(“Number of spaces available updated.”);
window.location.reload(true);
}
else
{
alert(“Problem retrieving XML data”);
}
}
}
function addClass(date,spaces) {
longdate = longDate(date.value);
reformatdate = reformatDate(date.value);
infoURL = “demo.php”;
load_external(infoURL,add_classes(longdate,spaces));
}
function add_classes(longdate,spaces) {
if (xmlhttp.readyState==4)
{// 4 = “loaded”
if (xmlhttp.status==200)
{// 200 = OK
alert(“Class for ” + longdate + ” has been added with ” + (spaces.selectedIndex+1) + ” spaces.”);
window.location.reload(true);
}
else
{
alert(“Problem retrieving XML data”);
}
}
}
The updateCurrentClasses function performs as it is supposed to. The addClass function does not, although they are almost identical.
Any ideas?