473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

external .js page

Hi i am new to javascript, (two weeks ) I have some programming
experience, this is what i want to do.

I have a small script (it prints the date in the UK fashion ) that i
want to include on several but not all the pages on my web site.
it seems illogical to type all the code on every page, I understand I
can put the code in a file lets call it do_date.js and have it used by
the pages it is needed on, i just don't seem to be able to get it to
work, suggestions would be most welcome>
Trev
Jul 20 '05 #1
6 1255
Trevor Stapleton wrote:

Hi i am new to javascript, (two weeks ) I have some programming
experience, this is what i want to do.

I have a small script (it prints the date in the UK fashion ) that i
want to include on several but not all the pages on my web site.
it seems illogical to type all the code on every page, I understand I
can put the code in a file lets call it do_date.js and have it used by
the pages it is needed on, i just don't seem to be able to get it to
work, suggestions would be most welcome>
Trev


Trev,

As a newbie, you'd do good to read the FAQ of this newsgroup....:
http://www.jibbering.com/faq/

But just to help you on your way (code presumes you put your js include
files in a seperate directory called "include"):

If you wrap the code in a function, include the following in the <HEAD>
of each HTML doc:
<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript"
SRC="include/do_date.js"></SCRIPT>

In the <BODY> of each HTML doc in the location where you want the
snippet to show, put:
<SCRIPT TYPE="text/javascript"
LANGUAGE="JavaScript">functionname();</SCRIPT>

If you don't wrap the code in a function, you can leave the bit in the
<HEAD> and just add the following in the HTML document at the right
place :
<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript"
SRC="include/do_date.js"></SCRIPT>

Good luck, Juliette
Jul 20 '05 #2
On Sat, 31 Jan 2004 23:14:39 +0000, Trevor Stapleton
<tr**************@ntlworld.com> wrote:
Hi i am new to javascript, (two weeks ) I have some programming
experience, this is what i want to do.

I have a small script (it prints the date in the UK fashion ) that i
want to include on several but not all the pages on my web site.
it seems illogical to type all the code on every page, I understand I
can put the code in a file lets call it do_date.js and have it used by
the pages it is needed on, i just don't seem to be able to get it to
work, suggestions would be most welcome>
Trev


My sites happen to make use of a couple of .js include files to handle
things like price conversion, should you want to take a look.

Also my automatic order forms display the day and date, which sounds
like what you are trying to do.

This is the code that I use...

var Months=new Array ("January","February","March","April","May",
"June","July","August","September","October","Nove mber","December");

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

function ShowDate()
{
var today = new Date();
var year=today.getYear();
if (year < 500)
year = year + 1900;
document.write(
Days[today.getDay()] + ", " +
today.getDate() + " " +
Months[today.getMonth()] + ", " +
year+".");
}

Cardman
http://www.cardman.com
http://www.cardman.co.uk
Jul 20 '05 #3
On Sun, 01 Feb 2004 00:25:33 +0100, Juliette
<"jrf[spamblock]"@jokeaday.net> wrote:
http://www.jibbering.com/faq/

But just to help you on your way (code presumes you put your js include
files in a seperate directory called "include"): Good luck, Juliette


Thank you for your speedy reply, I now have my script up and running
the pain problem was i had left a </SCRIPT> in the .js file and on the
page.

Thank you once again to for taking the time and trouble of answering
my question, i have visited the above web site as suggested.

Jul 20 '05 #4
On Sun, 01 Feb 2004 02:08:34 +0000, Cardman <do****@spam-me.com>
wrote:
Thanks for the reply, I have found the reason the script would not
work
it was a human error, mine, I had left a </SCRIPT> on the .js file
as well as on the page, one to many ( now were have I heard that
before?) thanks for the code and the reply
Jul 20 '05 #5
On Sun, 01 Feb 2004 13:26:43 +0000, Trevor Stapleton
<tr**************@ntlworld.com> wrote:
Thanks for the reply, I have found the reason the script would not
work it was a human error, mine,
Well that happens sometimes due to "bug" errors, either due to typing
too fast, not checking well enough, or your brain stops working for a
short time. :-]

Your problem though was due to learning about JavaScript, when
everyone has to learn sometime.

Currently have just started on Perl and CGI myself, where I am getting
nowhere quickly. I think that I will have to ask my hosting provider
just where they have left Perl on my system, when CGI only works with
compiled files so far.

If only I had Telnet access...
I had left a </SCRIPT> on the .js file
as well as on the page,
Yes I did that once, when first using include files, but I spotted the
problem quite quickly.

The problem I expect occurs by seeing JavaScript outside of <SCRIPT>
</SCRIPT> statements, which is just not normal.
one to many ( now were have I heard that
before?) thanks for the code and the reply


Good luck with the rest of your project then.

Cardman
http://www.cardman.com
http://www.cardman.co.uk
Jul 20 '05 #6
JRS: In article <r6********************************@4ax.com>, seen in
news:comp.lang.javascript, Trevor Stapleton <tr**************@ntlworld.c
om> posted at Sat, 31 Jan 2004 23:14:39 :-

I have a small script (it prints the date in the UK fashion ) that i
want to include on several but not all the pages on my web site.
it seems illogical to type all the code on every page, I understand I
can put the code in a file lets call it do_date.js and have it used by
the pages it is needed on, i just don't seem to be able to get it to
work, suggestions would be most welcome>


<URL:http://www.merlyn.demon.co.uk/js-nclds.htm>
<URL:http://www.merlyn.demon.co.uk/js-dates.htm>
<URL:http://www.merlyn.demon.co.uk/js-index.htm>

But, unless you are forced to do so, don't use DD/MM/YYYY ; use the ISO-
8601 format YYYY-MM-DD which everyone can understand.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Richard Speiss | last post by:
I am trying to display a random background image for a webpage. I found this code to do it <% 'Defines the number of background images you have Const NUMBER_OF_IMAGES = 2 'Initiates the...
1
by: John B. | last post by:
In an effort to turn a little more a module with my pages, I would like to turn my internal javascripts into an external javascript files to supply the information onto a web page. I...
1
by: Chuck Mendell | last post by:
I am having problem with external javascripts. My OS is XP Pro. I am told to create an external javascript using a .js extension. (I did that) The external .js is very simple, containing: ...
0
by: sub | last post by:
I'm using plone primary as a news system for my school. Now I want to integrate external sources into my plone site. The page is...
2
by: ras26 | last post by:
I have a WebSite "App1" which has an external assembly "Lib1". Inside this external assembly we have developed some classes that derive from "System.Web.UI.Page". One of these pages is called...
3
by: lookaround | last post by:
Hi everyone, I need some help... I call an external exe (a command-line tool) with Process.Start through this code: try { p = new Process(); p.StartInfo.UseShellExecute = false;...
4
by: fmaxwell | last post by:
Dear Group I have a very frustrating problem. I have been trying to make it more difficult to access external javascript files by using PHP sessions. This works beautifully locally (both in...
5
by: althafexcel | last post by:
hi everyone Im trying to include an external js in my aspx page under the head tag, it doesn't load or it displays an object expected error whenver the function from the .js is called. Actually...
20
by: Mark Anderson | last post by:
Hi, I have this in an external JS library: ///////////////////////// function addMyEvent(){ var obj; if(document.attachEvent) { obj = document.getElementsByTagName('img'); for...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.