Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split js into seperate file

Status
Not open for further replies.

scriggs

IS-IT--Management
Joined
Jun 1, 2004
Messages
286
Location
GB
Hi

I have some js which is currently in the header of the page and works perfectly. When I take the js, put it in a seperate file and set that as src="testimonials.js" it doesn't work.

Any clues?

Code:
var NS4 = (document.layers) ? 1 : 0;
var IE4 = (document.all) ? 1 : 0;

onload = start;

var ar = new Array();
ar[0] = "Quote1";
ar[1] = "Quote2";
ar[2] = "Quote3";
ar[3] = "Quote4";

var num = 0;

function start() {
  setInterval("update()", 1000); //Sets interval for update in 1000 of a second, i.e. 4000 = 4 seconds
}

function update() {
  display("banner", ar[num]);
  num++;
  if (num == ar.length) num = 0;
}

function display(id, str) {
  if (num%2) str = "<font color=red>" + str + "<font>"; //Makes every second quote appear in red
  if (NS4) {
    with (document[id].document) {
      open();
      write(str);
      close();
    }
  } else {
    document.all[id].innerHTML = str;
  }
}
 
Is there any other scripting on the page that could be affecting this?

Are you sure you are including the file correctly? Do you use the right path to the file, and have the pathname and/or filename in the right case ("testimonials.js" and "Testimonials.js" would be different files on some operating systems).

Hope this helps,
Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Incidentally, this is how you should be including the file, assuming it is in the same directory as the calling file, and the filename has a lower-case "t":

Code:
<script type="text/javascript" src="testimonials.js"></script>

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks, I did have an error in my calling. All sorted now thanks...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top