Discount Perfume - Debt Consolidation - Synchronize your Files - Debt Consolidation - Skype

PDA

View Full Version : putting javascript in external files


Vic_mackey
May 12th 2008, 2:01 am
Okay I have a problem with this. A design company sent me a new website I'd had done, but they've used javascript in the code itself rather than call it from external files. Its just a javascript to show the current time.

To start with it looked like this:


<td height="15" class="white-medium-text"><script language="javascript" type="text/javascript">
function MakeArrayday(size) {
this.length = size;
for(var i = 1; i <= size; i++) {
this[i] = "";
}
return this;
}
function MakeArraymonth(size) {
this.length = size;
for(var i = 1; i <= size; i++) {
this[i] = "";
}
return this;
}
function funClock() {

var runTime = new Date();
var hours = runTime.getHours();
var minutes = runTime.getMinutes();
var seconds = runTime.getSeconds();
var dn = "AM";
if (hours >= 12) {
dn = "PM";
hours = hours - 12;
}
if (hours == 0) {
hours = 12;
}
if (minutes <= 9) {
minutes = "0" + minutes;
}
if (seconds <= 9) {
seconds = "0" + seconds;
}
movingtime = "<b>"+ hours + ":" + minutes + ":" + seconds + " " + dn + "</b>";
document.getElementById('clock').innerHTML = movingtime;
setTimeout("funClock()", 1000)
}
window.onload = funClock;
// End -->
</script>
<script language="javascript" type="text/javascript">
<!-- Begin
function MakeArrayday(size) {
this.length = size;
for(var i = 1; i <= size; i++) {
this[i] = "";
}
return this;
}
function MakeArraymonth(size) {
this.length = size;
for(var i = 1; i <= size; i++) {
this[i] = "";
}
return this;
}
function funClock() {

var runTime = new Date();
var hours = runTime.getHours();
var minutes = runTime.getMinutes();
var seconds = runTime.getSeconds();
var dn = "AM";
if (hours >= 12) {
dn = "PM";
hours = hours - 12;
}
if (hours == 0) {
hours = 12;
}
if (minutes <= 9) {
minutes = "0" + minutes;
}
if (seconds <= 9) {
seconds = "0" + seconds;
}
movingtime = hours + ":" + minutes + ":" + seconds + " " + dn ;
document.getElementById('clock').innerHTML = movingtime;
setTimeout("funClock()", 1000)
}
window.onload = funClock;
// End -->
</script>
<span id=clock style="position:relative;"></span>

So its two javascripts. I put the first one in an external file and changed the first part to:
<td height="15" class="white-medium-text"><script type="text/javascript" src="clock.js"></script>

It worked fine like this. Now when I put the 2nd part into another external script, the clock isn't displaying. I dont want to leave the page full of javascript code, I'd prefer to get the 2nd part in an external file. Can anyone say why it is not working?

thanks

apmsolutions
May 12th 2008, 6:46 am
Is this on a public web site? Possible to see it in action?

GreatMetro
May 12th 2008, 10:41 pm
Try adding:

// <![CDATA[

right after the opening script tag, and

// ]]>

right before the closing script tag at the bottom

Vic_mackey
May 13th 2008, 3:27 pm
Thanks I'll try that, I'm off to football for a couple of days and leaving soon so will try as soon as I get back. apmsolutions sorry but its not a public site.