Web Design Forum  
 
Go Back   Web Design Forum > Web Software > Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 09-02-2009, 07:45 AM   #1
New Member
 
Join Date: Sep 2009
Posts: 1
Default onload problem

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&auml;sare st&ouml;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.
Jimmit is offline   Reply With Quote


Old 10-07-2009, 01:27 PM   #2
New Member
 
Jecht's Avatar
 
Join Date: Jul 2007
Location: Livorno, Italy
Posts: 5
Default

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]
Jecht is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 01:12 PM.


Camera Forum - Computer Forum - Web Design Forum

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.