Contact Us Forum Rules Search Archive
WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Site Design > Graphics & Design Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Graphics & Design Discussion Forum Post your graphics design questions/comments/ideas in here. Ask questions, post tutorials, discuss trends and best practices. Sub-forum for website accessibility and usability.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-28-2006, 12:36 PM
WebProWorld New Member
 

Join Date: Jan 2004
Location: Calgary
Posts: 17
rmac RepRank 0
Default Help needed to reference external javascript

I want to make a .js file containing javascript for the date on my website. I can add the file to the root dirtectory but I do not know how to reference the .js file so it appears on the page where I want it.

Any help would be appriciated.
Reply With Quote
  #2 (permalink)  
Old 04-28-2006, 02:45 PM
sands's Avatar
WebProWorld Veteran
 

Join Date: Sep 2005
Location: Kerala, India
Posts: 397
sands RepRank 1
Default

Add the following line in the head of the document:
<script language="javascript" type="text/javascript" src="date.js"></script>
This would point to the .js file presuming it is named date.js.

Then add the following wherever you wish to see the date on the document:
<script language="JavaScript" type="text/javascript">print_date()</script>
This presuming the function called is named print_date(). That is all!
__________________
My Nook | My Biz | My Photos
Reply With Quote
  #3 (permalink)  
Old 04-28-2006, 03:30 PM
WebProWorld New Member
 

Join Date: Jan 2004
Location: Calgary
Posts: 17
rmac RepRank 0
Default

I am still doing something wrong. I named the script date.js (see script below)

<SCRIPT language=JavaScript>
<!--
// Insert current date

now = new Date();
day = now.getDay();
var dayname;
if (day == 0) dayname = "Sunday";
if (day == 1) dayname = "Monday";
if (day == 2) dayname = "Tuesday";
if (day == 3) dayname = "Wednesday";
if (day == 4) dayname = "Thursday";
if (day == 5) dayname = "Friday";
if (day == 6) dayname = "Saturday";
month = now.getMonth();
var monthname;
if (month == 0) monthname = "January";
if (month == 1) monthname = "February";
if (month == 2) monthname = "March";
if (month == 3) monthname = "April";
if (month == 4) monthname = "May";
if (month == 5) monthname = "June";
if (month == 6) monthname = "July";
if (month == 7) monthname = "August";
if (month == 8) monthname = "September";
if (month == 9) monthname = "October";
if (month == 10) monthname = "November";
if (month == 11) monthname = "December";
date = now.getDate();
year = now.getYear();
if (year < 1000) year += 1900;

document.write("<FONT SIZE=2 face=arial,helvetica,univers,sanserif color=black>" + dayname + ", " + monthname + " " + date + ", " + year + "</FONT>");
// -->

</SCRIPT>

But I am still getting errors. I am unsure of the referencing part of it.
Reply With Quote
  #4 (permalink)  
Old 04-28-2006, 09:56 PM
sands's Avatar
WebProWorld Veteran
 

Join Date: Sep 2005
Location: Kerala, India
Posts: 397
sands RepRank 1
Default

Put this code into the .js file named date.js:
==================
<!--
// Insert current date

now = new Date();
day = now.getDay();
var dayname;
if (day == 0) dayname = "Sunday";
if (day == 1) dayname = "Monday";
if (day == 2) dayname = "Tuesday";
if (day == 3) dayname = "Wednesday";
if (day == 4) dayname = "Thursday";
if (day == 5) dayname = "Friday";
if (day == 6) dayname = "Saturday";
month = now.getMonth();
var monthname;
if (month == 0) monthname = "January";
if (month == 1) monthname = "February";
if (month == 2) monthname = "March";
if (month == 3) monthname = "April";
if (month == 4) monthname = "May";
if (month == 5) monthname = "June";
if (month == 6) monthname = "July";
if (month == 7) monthname = "August";
if (month == 8) monthname = "September";
if (month == 9) monthname = "October";
if (month == 10) monthname = "November";
if (month == 11) monthname = "December";
date = now.getDate();
year = now.getYear();
if (year < 1000) year += 1900;
theDate = "<FONT SIZE=2 face=arial,helvetica,univers,sanserif color=black>" + dayname + ", " + monthname + " " + date + ", " + year + "</FONT>";
// -->
==================

Then put this line in the head of the HTML document:
==================
<script language="javascript" type="text/javascript" src="date.js"></script>
==================

Then add this line wherever you wish to see the date in the HTML document:
==================
<script language="JavaScript" type="text/javascript">document.write(theDate)</script>
==================
__________________
My Nook | My Biz | My Photos
Reply With Quote
  #5 (permalink)  
Old 04-28-2006, 09:57 PM
WebProWorld Veteran
 

Join Date: Aug 2003
Location: California,USA
Posts: 373
drummin RepRank 0
Default

Just use the script itself without heading and ending. So remove the head (<SCRIPT language=JavaScript>) and ending (</SCRIPT>) from your js file. The name of the file tells what kind of file it is just like you wouldn't add <style type="text/css"> to a css file.

<!--
// Insert current date

now = new Date();
day = now.getDay();
var dayname;
if (day == 0) dayname = "Sunday";
if (day == 1) dayname = "Monday";
if (day == 2) dayname = "Tuesday";
if (day == 3) dayname = "Wednesday";
if (day == 4) dayname = "Thursday";
if (day == 5) dayname = "Friday";
if (day == 6) dayname = "Saturday";
month = now.getMonth();
var monthname;
if (month == 0) monthname = "January";
if (month == 1) monthname = "February";
if (month == 2) monthname = "March";
if (month == 3) monthname = "April";
if (month == 4) monthname = "May";
if (month == 5) monthname = "June";
if (month == 6) monthname = "July";
if (month == 7) monthname = "August";
if (month == 8) monthname = "September";
if (month == 9) monthname = "October";
if (month == 10) monthname = "November";
if (month == 11) monthname = "December";
date = now.getDate();
year = now.getYear();
if (year < 1000) year += 1900;

document.write("<FONT SIZE=2 face=arial,helvetica,univers,sanserif color=black>" + dayname + ", " + monthname + " " + date + ", " + year + "</FONT>");
// -->
Reply With Quote
  #6 (permalink)  
Old 05-15-2006, 10:08 AM
Faglork's Avatar
WebProWorld Veteran
 

Join Date: Feb 2005
Location: Forchheim, Germany
Posts: 947
Faglork RepRank 0
Default

Quote:
Originally Posted by sands
Add the following line in the head of the document:
<script language="javascript" type="text/javascript" src="date.js"></script>
This would point to the .js file presuming it is named date.js.
If the script resides in the root directory, I suggest to use
Code:
<script language="javascript" type="text/javascript" src="/date.js"></script>
instead. This will work from all subdirectories as well.

hth,
faglork
Reply With Quote
  #7 (permalink)  
Old 05-16-2006, 12:43 AM
WebProWorld Pro
 

Join Date: May 2004
Location: Flagstaff, AZ
Posts: 178
Jeff Colburn RepRank 0
Default

Hi,

Another way to add JavaScript to a page is with Server Side Includes. Go here http://www.creativecauldron.com/websitearticleSSI.shtml and read my article "Use Server Side Includes To Ease Your Workload."

Have Fun,
Jeff
__________________
Visit The Creative Cauldron at http://www.CreativeCauldron.com You'll find reports, ebooks, events, retreats, a blog and much more.
Reply With Quote
Reply

  WebProWorld > Site Design > Graphics & Design Discussion Forum
Tags: , , , ,



Thread Tools
Display Modes

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

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


Search Engine Optimization by vBSEO 3.2.0