...

View Full Version : getElementById won't work on Personal Computer



Brett Bretterso
10-13-2005, 01:56 PM
I've done a lot with getElementById, but right now I'm at home and decided to do a little scripting. I tried to do something and it wouldn't work, and I've isolated the problem to being that getElementById just won't work. When the page calls a function in a .js file that does document.getElementById it gives an error whenever I try to touch the gotten element's attributes. If I do document.getElementById on the page it simply ignores it. It doesn't throw an error, but it also won't do what it says.

The only thing I can think of for why is that it's because the html file is on my personal computer rather than a server, which I didn't think would matter because javascript is run client side.

Does anyone have any ideas why it isn't working?

Here's my code:



<script src="javascripts/clocks.js" language="javascript"></script>
<script language="javascript">
window.onLoad = new function(){
displayDatum("oDiv1");

document.getElementById("oDiv1").innerHTML="hola";
}
</script>
</head>

<body bgcolor="#7B99E1">
<div ID="oDiv1" style="background-color:#FFFFFF ">hello</div>
</body>

I also tried window.alert(document.getElementById("oDiv1").innerHTML); and it just ignored it, where it gladly did window.alert("hola");.

Any ideas would be appreciated.

Brett Bretterson

Bill Posters
10-13-2005, 02:20 PM
window.onload = function() {

_Aerospace_Eng_
10-13-2005, 02:35 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
background-color:#7B99E1;
}
#oDiv1 {
background-color:#FFFFFF;
}
-->
</style>
<script type="text/javascript">
<!--
window.onload = function(){
//displayDatum("oDiv1"); This seems to cause it not to run.

document.getElementById("oDiv1").innerHTML="hola";
}
//-->
</script>
</head>

<body>
<div id="oDiv1">hello</div>
</body>
</html>
Where is displayDatum defined?

Brett Bretterso
10-13-2005, 03:12 PM
<script src="javascripts/clocks.js" language="javascript"></script>
<script language="javascript">
window.onload = new function(){
displayDatum("oDiv1");

document.getElementById("oDiv1").innerHTML="hola";
}
</script>
</head>

<body bgcolor="#7B99E1">
<div ID="oDiv1" style="background-color:#FFFFFF ">hello</div>
</body>

Sorry, the capital L was a typo. displayDatum("oDiv1"); is in my clocks.js file. I've tried running the page with that line commented out and document.getElementById("oDiv1").innerHTML="hola"; still won't work.

Bill Posters
10-13-2005, 03:55 PM
Sorry, the capital L was a typo. displayDatum("oDiv1"); is in my clocks.js file. I've tried running the page with that line commented out and document.getElementById("oDiv1").innerHTML="hola"; still won't work.
Have you also tried removing the new as in both of the examples posted?

Brett Bretterso
10-13-2005, 04:16 PM
Doh!

Thanks a lot,

Brett Bretterson



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum