Jump to content

Script & Tables


nutterz
 Share

Recommended Posts

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...