Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Aug 2005
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    getElementById won't work on Personal Computer

    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:


    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

  • #2
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Code:
    window.onload = function() { …

  • #3
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Code:
    <!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?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #4
    New Coder
    Join Date
    Aug 2005
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>
    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.

  • #5
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Quote Originally Posted by Brett Bretterso
    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?

  • #6
    New Coder
    Join Date
    Aug 2005
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Doh!

    Thanks a lot,

    Brett Bretterson


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •