I am using some common Javascript functions I wrote that are required in several pages. I would prefer to have the functions in a single .js file and link to this file from the required web pages. How do I link to such a file ? I tried the same method as linking to a Stylesheet file, but it is not working.

<Link Href="MainStyles.css" rel="Stylesheet" type="text/css">

This is working fine

<LINK HREF="GenJS.js" type="text/javascript">

This is not working.

The contents of the GenJS.js file is

<SCRIPT Language="Javascript">

function Gablu()
{
	alert ("Hullo") ;
}


</SCRIPT>

When I am trying to refer to the function Gablu(), I am getting the error 'Object Required'

<script src="GenJS.js" type="text/javascript"></script>

Use the code given by stymiee; also, take the <SCRIPT Language="Javascript"> and </SCRIPT> tags out of the .js file... they are not needed in this case.

Plus you can safely do away with the language='javascript' attribute since Javascript is the default scripting engine for all browsers. Use this tag only when you are using two or more scripting languages. Eg. VBScript etc.

Thanks Stymiee, MattEvans and ~S.O.S~ .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.