External Javascript

This is a discussion on "External Javascript" within the JavaScript Forum section. This forum, and the thread "External Javascript are both part of the Program Your Website category.



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

Notices


Closed Thread
 
LinkBack Thread Tools
  #1 (permalink)  
Old Aug 9th, 2004, 18:23
New Member
Join Date: Aug 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to MikeV
External Javascript

Hi,

I've read on these forums that its good to put Javascript in an external .js file so that the page size is smaller. I've tried putting the following bit of Javascript (which prints put the date) into an external file but how can I then reference it to put the date into the right place on my page? Is this just the kind of Javascript that I cant make external to a page?

Any help would be appreciated.

Mike

<script type="text/javascript" language="JavaScript1.2"><!--

var mydate=new Date()

var year=mydate.getYear()

if (year < 1000)

year+=1900

var day=mydate.getDay()

var month=mydate.getMonth()

var daym=mydate.getDate()

if (daym<10)

daym="0"+daym

var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thu rsday","Friday","Saturday")

var montharray=new Array("January","February","March","April","May"," June","July","August","September","October","Novem ber","December")

document.write("<font color='ffffff' face='verdana' size='1'>"+montharray[month]+" "+daym+", "+year+"<\/b>")

// -->
</script>

  #2 (permalink)  
Old Aug 9th, 2004, 21:34
benbacardi's Avatar
Highly Reputable Member
Join Date: Feb 2004
Location: United Kingdom
Age: 20
Posts: 611
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to benbacardi Send a message via Skype™ to benbacardi
that sort of javascript, with the document.write(), you can't put in an external javascript file. However, you can do this:

You can put the string that you want to write into the page in an external javascript file in a variable like this:

Code: Select all
var mydate=new Date()

var year=mydate.getYear()

if (year < 1000)

year+=1900

var day=mydate.getDay()

var month=mydate.getMonth()

var daym=mydate.getDate()

if (daym<10)

daym="0"+daym

var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")

var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")

datestring = "<font color='ffffff' face='verdana' size='1'>"+montharray[month]+" "+daym+", "+year+"<\/b>";
and then just write it to the page with this code exactly where you want it on the page:

Code: Select all
<script type="text/javascript" language="JavaScript1.2">
<!--

document.write(datestring);

//-->
</script>
just dont forget to add in the <head>:

Code: Select all
<script type="text/javascript" language="JavaScript1.2" src="external.js">
where external.js is the name of your external javascript file
  #3 (permalink)  
Old Aug 9th, 2004, 23:50
New Member
Join Date: Aug 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to MikeV
Ben,

Many thanks for your help. I've put that code in and its much neater. At the moment I'm copying and pasting into Dreamweaver 3. Do you know of any good software for debugging javascript (preferably free)?

Mike
  #4 (permalink)  
Old Aug 10th, 2004, 08:07
benbacardi's Avatar
Highly Reputable Member
Join Date: Feb 2004
Location: United Kingdom
Age: 20
Posts: 611
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to benbacardi Send a message via Skype™ to benbacardi
I don't myself, all I ever use to make my websites is good old Notepad!!
  #5 (permalink)  
Old Aug 10th, 2004, 15:28
Rob's Avatar
Rob Rob is offline
Head Admin & CEO

SuperMember
Join Date: Jul 2003
Location: at my desk
Age: 34
Posts: 2,952
Blog Entries: 7
Thanks: 7
Thanked 4 Times in 4 Posts
Send a message via MSN to Rob Send a message via Skype™ to Rob
<blockquote id="quote" class="ffs">quote:<hr height="1" noshade="noshade" id="quote" />Originally posted by benbacardi
I don't myself, all I ever use to make my websites is good old Notepad!!<hr height="1" noshade="noshade" id="quote" /></blockquote id="quote">and I thought I was the ONLY one..... :wink:
__________________
Rob - SEO Specialist
Owner & Founder of Webforumz.com

I am currently unavailable for private work
  #6 (permalink)  
Old Aug 11th, 2004, 08:12
benbacardi's Avatar
Highly Reputable Member
Join Date: Feb 2004
Location: United Kingdom
Age: 20
Posts: 611
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to benbacardi Send a message via Skype™ to benbacardi
hey! me too! good to know theres other weirdos like me out there who like the hard work :wink:
Closed Thread

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
External HD Ryan Fait Webforumz Cafe 16 Jan 11th, 2008 13:28
external javascript problem Damian PHP Forum 0 Dec 5th, 2007 09:44
external js alexgeek JavaScript Forum 6 Sep 23rd, 2007 20:57
Problem with IE, think its external javascript includes rewind1000 JavaScript Forum 5 Aug 19th, 2005 12:00


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


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