nutterz Posted June 20, 2009 Share Posted June 20, 2009 Hey im trying to piece together a script that i can edit to use as an organiser for my homepage im working on and cant seem to figure out how to put the code into the table i want it in. here is what i got below.<table class="one"><tr></tr><tr><td class="one"><script type="text/javascript">var d=new Date();theDay=d.getDay();switch (theDay){ case 0: document.write("Sunday"); break; case 1: document.write("Monday"); break; case 2: document.write("Tuesday"); break; case 3: document.write("Wednesday"); break; case 4: document.write("Thursday"); break; case 5: document.write("Friday"); break; case 6: document.write("Saturday"); break; case 7: document.write("Sunday"); break; default: document.write("This should not be written here, unless a new day was added to the calendar");}</script></td></tr> </table> Link to comment Share on other sites More sharing options...
Ingolme Posted June 20, 2009 Share Posted June 20, 2009 You probably don't actually need tables for this, and PHP would serve better than Javascript.But answering your specific question: put your Javascript outside the table element and access it. I'll simplify your Javascript to not take up so much space. <table class="one"><tr></tr><tr><td id="weekday"></td></tr></table><script type="text/javascript">var weekdays = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];var d = new Date();document.getElementById("weekday").innerHTML = weekdays[d.getDay()];</script> Here's how I'd do it with PHP and without tables: <div class="one"><?php echo date("l"); ?></div> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.