|
|
#1 |
|
New Member
![]() Join Date: Sep 2009
Posts: 1
|
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')"> 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);
}
}
}
|
|
|
|
|
|
#2 |
|
New Member
![]() Join Date: Jul 2007
Location: Livorno, Italy
Posts: 5
|
Try to setup a timeout. Maybe your script works but the recipient isn't load yet...
HTML Code:
<body onload="setTimeout(openThis('blog.php?id=1'),100);">
__________________
[SIGPIC][/SIGPIC] |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|