Inconsistent working of html code(Solved)

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Inconsistent working of html code(Solved)

Post 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
Last edited by raghavan20 on Sun Aug 14, 2005 12:12 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your "host" injects this:

Code: Select all

window.onload = check_banner;
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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"
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post 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>
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post 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>
Post Reply