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 Quote Link to comment 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 } Quote Link to comment Share on other sites More sharing options...
shaunmckinnon Posted June 30, 2008 Author Share Posted June 30, 2008 thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.