This is a discussion on "External JS Date" within the JavaScript Forum section. This forum, and the thread "External JS Date are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
External JS Date
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
External JS Date
Hi there I am new to js and i am starting with a simple date to put it on my site. I want it to be an external file and i want to call it from each page so the size will be more smaller and much nicer ..anyway.
This is the date code; function GetMonth(intMonth){ var MonthArray = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December") return MonthArray[intMonth] } function getDateStr(){ var today = new Date() var year = today.getYear() if(year<1000) year+=1900 var todayStr = GetMonth(today.getMonth()) + " " + today.getDate() todayStr += ", " + year return todayStr } And i dont know how to call it from the main HTML file. If i were to put it on the same file then I would use the <SCRIPT Language="JavaScript"> document.write(getDateStr()) </SCRIPT> To call the function. But the file is external and how do I call the file ? and display the date ? |
|
|
|
|||
|
Re: External JS Date
I am using the folowing html code in order to get the date displayed from an external file but it only displays the TEXT. Is not executing the js function.
I have included the full path where the js file is and still doesnt work. Exactly on the (src="date.js" ) part still is not working any suggestion. <HTML> <HEAD> <TITLE>My Home Page</TITLE> </HEAD> <BODY> <H1>My Home Page</H1> Hi There! <br><br> <script type="text/javascript" src="date.js"></script> </BODY> </HTML> |
|
||||
|
Re: External JS Date
The external script call goes in the head section.
|
|
||||
|
Re: External JS Date
I don't believe that matters... but I never put it outside of the head, so I could be wrong
|
|
|||
|
Re: External JS Date
This is not working for me I tryed everything.
I have put the date function into a js file. And this is what it looks like. -------------------------------------------------------------------- function GetMonth(intMonth){ var MonthArray = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December") return MonthArray[intMonth] } function getDateStr(){ var today = new Date() var year = today.getYear() if(year<1000) year+=1900 var todayStr = GetMonth(today.getMonth()) + " " + today.getDate() todayStr += ", " + year return todayStr } -------------------------------------------------------------------- And I have included the link on the head section, but and it doesnt work. Do I add something else in the body section in order to call the function ??? I also tryed to call it from the body section by simply adding the link to the external file and still didnt work any ideas and feedback ?? |
|
||||
|
Re: External JS Date
Put the external script tags in the header, then call it where you want the date to show up with this:
|
![]() |
| Tags |
| external javascript |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Changing date format in date picker | AdRock | JavaScript Forum | 1 | Aug 1st, 2006 17:16 |
| Date in Asp | Gup | Classic ASP | 1 | Jun 5th, 2006 09:05 |
| asp date | Monie | Classic ASP | 1 | Sep 21st, 2004 04:38 |
| date format help please | charter | Databases | 3 | Jun 14th, 2004 20:09 |
| Date Validation | señorbadger | JavaScript Forum | 1 | Nov 17th, 2003 19:48 |