...

View Full Version : how do you position a javascript date in a html table?



robe01
03-29-2012, 01:51 AM
So I've now made the layout of my website and I need to know how to position a javascript date I made, in a html table. This is the basic "var d=new date();" code I'm trying to implement in the menu section of my website. Also, I need to know how to do this using an external javascript file.

Nile
03-29-2012, 01:54 AM
Can you elaborate on what you want please?

Old Pedant
03-29-2012, 01:57 AM
var months = ["Jan","Feb","Mar",...];
function setDateInPlace( )
{
var now = new Date();
var dateAsString = months[now.getMonth()] + " " + now.getDate() + ", " + now .getFullYear();
document.getElementById("whereTheDateGoes").innerHTML = dateAsString;
}
window.onload = setDateInPlace(); // better would be to use attachEvent


So make your HTML look pretty, maybe


<div id="whereTheDateGoes" class="someThingFancyNoDoubt">Feb 29, 2013</div>

and then let the JS code replace the pretty date and the replacement will look similarly pretty.

Nile
03-29-2012, 02:01 AM
Probably some mere quick-finger errors, but, on line 5, you're treating months as a function instead of an array. Also, in the HTML, the ID doesn't match the javascript target ID.

Old Pedant
03-29-2012, 02:09 AM
Thanks. One wrong language and one slipped finger. Fixed.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum