Barons Posted August 11, 2011 Share Posted August 11, 2011 Hi, I don't know anything about JS so I found some copy and paste code online telling me how to put a current date on my website. It works like a charm. the only issue is I have tons of code in the middle of my html page. I started trying to find out how to include it like you would a php file. I've got the part about creating a .js file without the script tags and I've got the part about adding stuff into the header of the page but them what? Anyone able to help me figure out what I need to stick in the middle of my div tags to make the date show up? I used the below site to tell me how to do what I've done so far. Its about mid way down on the page. http://www.netmechanic.com/news/vol5/html_no3.htm Here's where i'm at if it helps. Header: <script src="date.js" language="javascript" type="text/javascript"></script> date.js file: <!-- // Array of day names var dayNames = new Array("Sunday","Monday","Tuesday","Wednesday", "Thursday","Friday","Saturday"); // Array of month Names var monthNames = new Array( "January","February","March","April","May","June","July", "August","September","October","November","December"); var now = new Date(); document.write(dayNames[now.getDay()] + ", " + monthNames[now.getMonth()] + " " + now.getDate() + ", " + now.getFullYear()); // --> =( Lonely div tags: <div id="datetext"></div> Am I missing something major that will require me to lean how this stuff works? Hopefully its just a simple bit of code. If not I might just leave it the way it was. Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/244471-issue-external-js-files-trying-to-place-a-current-date-on-my-site/ Share on other sites More sharing options...
nogray Posted August 11, 2011 Share Posted August 11, 2011 You would need to create an onload event and instead of document.write, use document.getElementById('datetext').innerHTML = '....'; in the onload function. If you don't want to make an onload event, just move all your javascript files to the bottom of the page (above the </body> tag). Quote Link to comment https://forums.phpfreaks.com/topic/244471-issue-external-js-files-trying-to-place-a-current-date-on-my-site/#findComment-1255710 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.