C
cookieplanter
I need to add content to two DIVs on page load but this just won't
work. If I call any one function, things work fine or if I trigger the
events on-click, it works perfectly. But with both together on load,
nothing happens. Please help.
Krishna.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Hello, World!</title>
<script type="text/javascript">
divSwap = createR();
var globalDIV;
switchDiv('hello.htm', 'helloDiv');
switchDiv('goodbye.htm', 'goodbyeDiv');
function createR() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}
function switchDiv(url, divID) {
divSwap = createR();
globalDIV = divID;
divSwap.open('GET', url, true)
divSwap.onreadystatechange = switchResponse;
divSwap.send(null);
}
function switchResponse() {
if(divSwap.readyState == 4) {
if (divSwap.status == 200) {
doMagic();
}
}
}
function doMagic() {
var myresponse = divSwap.responseText;
document.getElementById(globalDIV).innerHTML=myresponse;
}
</script>
</head>
<body>
<p><a href="javascript:switchDiv('hello.htm', 'helloDiv');">Hello</a>
<a href="javascript:switchDiv('goodbye.htm',
'goodbyeDiv');">Goodbye</a></p>
<h1>krishna waz ere..</h1>
<div id="helloDiv"></div>
<h1>juss checking macha</h1>
<div id="goodbyeDiv"></div>
</body>
</html>
work. If I call any one function, things work fine or if I trigger the
events on-click, it works perfectly. But with both together on load,
nothing happens. Please help.
Krishna.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Hello, World!</title>
<script type="text/javascript">
divSwap = createR();
var globalDIV;
switchDiv('hello.htm', 'helloDiv');
switchDiv('goodbye.htm', 'goodbyeDiv');
function createR() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}
function switchDiv(url, divID) {
divSwap = createR();
globalDIV = divID;
divSwap.open('GET', url, true)
divSwap.onreadystatechange = switchResponse;
divSwap.send(null);
}
function switchResponse() {
if(divSwap.readyState == 4) {
if (divSwap.status == 200) {
doMagic();
}
}
}
function doMagic() {
var myresponse = divSwap.responseText;
document.getElementById(globalDIV).innerHTML=myresponse;
}
</script>
</head>
<body>
<p><a href="javascript:switchDiv('hello.htm', 'helloDiv');">Hello</a>
<a href="javascript:switchDiv('goodbye.htm',
'goodbyeDiv');">Goodbye</a></p>
<h1>krishna waz ere..</h1>
<div id="helloDiv"></div>
<h1>juss checking macha</h1>
<div id="goodbyeDiv"></div>
</body>
</html>