shaunmckinnon Posted June 30, 2008 Share Posted June 30, 2008 not sure what the problem is. everytime I run this script it tells me that the getElementById is undefined: <html> <head> <title>test</title> <script> // JavaScript Document //testing var var displayTest; //***256fX Calendar Widget*** //labels for the days of the week, names of the months, and number of days in each month days = new Array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"); months = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); noDays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); //fall back to today's date today = new Date(); var x = months.length; for(i=0; i<x; i++){ document.getElementById("testing").innerHTML="<br>"+months[i]+" - "+noDays[i]+"<br>"; } </script> </head> <body> <p id="testing"></p> </body> </html> any help would be appreciated. I'm quite new to Javascript, so it's probably something dumb. thanks, shaun Link to comment https://forums.phpfreaks.com/topic/112608-very-basic-getelementbyid-isssue/ Share on other sites More sharing options...
rhodesa Posted June 30, 2008 Share Posted June 30, 2008 The error is that the DOM element doesn't exist yet. Either move the JS to after the element, or wrap the JS code with a window.onload: window.onload=function(){ //JS code here } Link to comment https://forums.phpfreaks.com/topic/112608-very-basic-getelementbyid-isssue/#findComment-578307 Share on other sites More sharing options...
shaunmckinnon Posted June 30, 2008 Author Share Posted June 30, 2008 thanks. Link to comment https://forums.phpfreaks.com/topic/112608-very-basic-getelementbyid-isssue/#findComment-578313 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.