External JS Date

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.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Feb 20th, 2007, 15:44
New Member
Join Date: Feb 2007
Location: UK
Age: 28
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
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 ?
Reply With Quote

  #2 (permalink)  
Old Feb 20th, 2007, 22:35
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
Thanks: 0
Thanked 0 Times in 0 Posts
Re: External JS Date

Put the functions in a .js file, then link to it in the HTML.

<script type="text/javascript" src="getdate.js"></script>
Reply With Quote
  #3 (permalink)  
Old Feb 20th, 2007, 23:25
New Member
Join Date: Feb 2007
Location: UK
Age: 28
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
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>
Reply With Quote
  #4 (permalink)  
Old Feb 20th, 2007, 23:30
BGarner's Avatar
Reputable Member
Join Date: Oct 2006
Location: In front of the computer.
Posts: 213
Thanks: 0
Thanked 0 Times in 0 Posts
Re: External JS Date

The external script call goes in the head section.
Reply With Quote
  #5 (permalink)  
Old Feb 21st, 2007, 10:06
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
Thanks: 0
Thanked 0 Times in 0 Posts
Re: External JS Date

I don't believe that matters... but I never put it outside of the head, so I could be wrong
Reply With Quote
  #6 (permalink)  
Old Feb 22nd, 2007, 10:36
New Member
Join Date: Feb 2007
Location: UK
Age: 28
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
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 ??
Reply With Quote
  #7 (permalink)  
Old Feb 22nd, 2007, 22:38
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
Thanks: 0
Thanked 0 Times in 0 Posts
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:

Code: Select all
<script type="text/javascript">document.write(getDateStr());</script>
Reply With Quote
Reply

Tags
external javascript

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT. The time now is 19:43.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43