Page 1 of 1

Inconsistent working of html code(Solved)

Posted: Fri Aug 12, 2005 9:24 am
by raghavan20
I have got a html file which works fine when run on my local machine.
But when I upload the file to the hosting server and run it from there, it does not work the way it should.

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Chat Application - Retrieve messages</title>
<script language="javascript"> 
<!-- 
function alertDiv(){
	//alert (content.innerHTML);
	alert (document.getElementById("newDiv").innerHTML); 
}
//--> 
</script> 
<link href="chat1.css" rel="stylesheet" type="text/css" />
</head>

<body onload = 'alertDiv()'>

	<div id="newDiv" class="chatWindow" style="margin:200px;">
		Hi, all!!!
	</div>
</body>
</html>
Also try the file at:
http://raghavan20.allhyper.com/temp.html

Posted: Fri Aug 12, 2005 9:33 am
by feyd
your "host" injects this:

Code: Select all

window.onload = check_banner;

Posted: Fri Aug 12, 2005 9:34 am
by hawleyjr
On the site (Your link) The on body tag looks like this:

Code: Select all

//Note there are about 3 spaces before the alertDiv()
<body onload =' alertDiv()'>
Try something like this:

Code: Select all

<body onload="alertDiv();">
I have no idea if this will fix it or not. just an idea.

Posted: Fri Aug 12, 2005 12:40 pm
by raghavan20
feyd, what could be the problem if they have the window.onload event to call that function?
What has it go to do with an alert statement?
I actually wanted to read the content in the div,newDiv as soon as the page loads
<body onload = 'alertDiv()'
hi hawleyj, the above is wot I got when I viewed source of the file thats on the site.

Posted: Fri Aug 12, 2005 12:45 pm
by feyd
their injected overrides the event. Your code is not run, as you have seen. That line changes the onload event to their function "check_banner"

Posted: Fri Aug 12, 2005 1:29 pm
by raghavan20
I just have taken out that onload event function and trying to display the innerHTML of the div using alert() which does not happen.

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Chat Application - Retrieve messages</title>
<script language="javascript"> 
<!-- 
	alert (document.getElementById("newDiv").innerHTML); 
//--> 
</script> 
<link href="chat1.css" rel="stylesheet" type="text/css" />
</head>

<body>

	<div id="newDiv" class="chatWindow" style="margin:200px;">
		hi all!!!
	</div>
</body>
</html>

Posted: Fri Aug 12, 2005 1:59 pm
by PrObLeM
The above code wont work because the div isnt created when you try to call it. YEA ERROR MESSAGES!
Error: document.getElementById("newDiv") has no properties
Source File: http://raghavan20.allhyper.com/temp.html
Line: 8
but this is one way to fix it

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Chat Application - Retrieve messages</title>
<script language="javascript">
<!--
function callfunc() {
   alert (document.getElementById("newDiv").innerHTML);
}
//-->
</script>
<link href="chat1.css" rel="stylesheet" type="text/css" />
</head>

<body>

   <div id="newDiv" class="chatWindow" style="margin:200px;">
      hi all!!!
   </div>
<script language="javascript">
callfunc();
</script>
</body>
</html>