Hello!
I've got a problem when I try to set a value on a div with onload. I can't really see what the problem is. I'm pretty green on javascript.
This works: <a href="#" onclick="openThis('blog.php?id=1')">ID 1</a>
This doesn't: <body onload="openThis('blog.php?id=1')">
Maybe I should tell you that I fadeIn the div 'popup' with jquery.
I've got a problem when I try to set a value on a div with onload. I can't really see what the problem is. I'm pretty green on javascript.
This works: <a href="#" onclick="openThis('blog.php?id=1')">ID 1</a>
This doesn't: <body onload="openThis('blog.php?id=1')">
Code:
var xmlhttp;
function openThis(url) {
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp != null) {
xmlhttp.onreadystatechange = changeDiv;
xmlhttp.open("GET", url, true);
xmlhttp.send(null);
}
else {
alert("Din webbläsare stödjer inte XMLHTTP!");
}
}
function changeDiv() {
if (xmlhttp.readyState == 4) {
if(xmlhttp.status == 200) {
document.getElementById('popup').innerHTML = xmlhttp.responseText;
}
else {
alert("Problem med data:" + xmlhttp.statusText);
}
}
}
Maybe I should tell you that I fadeIn the div 'popup' with jquery.