This is making me go insane, bat shit insane.
I have a div, it has a dynamic name, like: "56546_div", I then have a javascript function called "button", the function is executed with an onclick:
<a href="#" onclick="button(56546);">click</a>
and my javascript
var xmlHttp
function button(id)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="file.php";
url=url+"?id="+id;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function stateChanged() {
document.getElementById(id+"_div").innerHTML=xmlHttp.responseText;
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
I've used this code eslewhere before and it works perfectly, but it won't work here. I have no idea what's wrong; I thought it might have been numbers in DIV but even if I create a div called "cat" and then hard code the javascript to change "cat" to "lol", it doesn't work.
The function definitely gets executed, I can see with firebug that it sends a query to the PHP with the id, but it doesn't change the div contents.
been trying for hours, any ideas?