/    Sign up×
Community /Pin to ProfileBookmark

Javascript help needed

I got this script for a world clock to put on my website, but when i place the respective body and head data, it does not seem to work on my website, although it works in a new page i create with dreamweaver. The image of the clock and the list of the countries appear, but the clock won’t tick.
I have added here the script from the blank page. any insight would help. thanks. if someone could IM me or email me with some information, i would very much appreciate it.

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
<style type=”text/css”>
<!–
body{
background-color:#000000;
}
#theContainer{
position:relative;width:120px;height:160px;text-align:center;
}
.handsanddotsstyle{
position:absolute;top:0px;left:0px;width:2px;height:2px;font-size:2px;background-color:#000000;
}
.ampmstyle{
position:absolute;top:0px;left:0px;width:20px;height:10px;text-align:center;font-family:arial,sans-serif;font-size:12px;color:#000000;
}
.datestyle{
position:absolute;top:0px;left:0px;width:100px;text-align:center;font-family:arial,sans-serif;font-size:10px;color:#000000;
}
.facestyle{
position:absolute;top:0px;left:0px;width:15px;height:15px;text-align:center;font-family:arial,sans-serif;font-size:10px;color:#000000;
}
.citystyle{
position:absolute;top:0px;left:0px;width:110px;height:20px;z-index:100;
}
.selectstyle{
width:110px;font-family:arial,sans-serif;font-size:12px;color:#ffffff;background:#000000;
}
//–>
</style>
</head>

<body>
<div id=”theContainer”>
<div id=”theCities” class=”citystyle”>
<p style=”margin:0px;”>
<select size=”1″ class=”selectstyle” id=”city” onchange=”lcl(this)”>
<option value=”0″ selected>Local time</option>
<option value=”0″>GMT</option>

<option value=”1″>Rome</option>
<option value=”2″>Cairo</option>

<option value=”3″>Moscow</option>
<option value=”3.30″>Tehran</option>

<option value=”5″>Karachi</option>
<option value=”5.30″>Bombay</option>
<option value=”7″>Bangkok</option>
<option value=”8″>Hong Kong</option>
<option value=”9″>Tokyo</option>
<option value=”9.30″>Darwin</option>
<option value=”10″>Sydney</option>
<option value=”12″>Fiji</option>
<option value=”-10″>Hawaii</option>

<option value=”-8″>San Francisco</option>
<option value=”-7″>Arizona</option>
<option value=”-5″>New York</option>
<option value=”-3.30″>Newfoundland</option>

<option value=”-3″>Greenland</option>
</select>
</p>
</div>

<script type=”text/javascript”>
<!– World Clock (No DST, standard time only!) [url]http://www.btinternet.com/~kurt.grigg/javascript[/url]

doesWhatsNeeded=((document.body) &&
document.body.firstChild);

if (doesWhatsNeeded){

fCol=’#ffffff’; //face/number colour.
dCol=’#777777′; //dot colour.
hCol=’#ffffff’; //hours colour.
mCol=’#ffffff’; //minutes colour.
sCol=’#ff0000′; //seconds colour.
cCol=’#ffffff’; //date colour.
aCol=’#777777′; //am-pm colour.
bCol=’#000000′; //select/form background colour.
tCol=’#ffffff’; //select/form text colour.

//Alter nothing below! Alignments will be lost!
y=87;
x=60;
h=3;
m=4;
s=5;
cf=new Array();
cd=new Array();
ch=new Array();
cm=new Array();
cs=new Array();
face=”3 4 5 6 7 8 9 10 11 12 1 2″;
face=face.split(” “);
n=face.length;
e=360/n;
hDims=30/4;
zone=0;
isItLocal=true;
ampm=””;
daysInMonth=31;
todaysDate=””;
var oddMinutes;
var getOddMinutes;
var addOddMinutes;
plusMinus=false;
var addPx=((document.compatMode != undefined) &&
document.compatMode.indexOf(“CSS”) != -1)?”px”:0;

document.write(‘<div id=”theDate” class=”datestyle” style=”color:’+cCol+'”>!</div>’);
document.write(‘<div id=”amOrPm” class=”ampmstyle” style=”color:’+aCol+'”>!</div>’);
for (i=0; i < n; i++){
document.write(‘<div id=”theFace’+i+'” class=”facestyle” style=”color:’+fCol+'”>’+face[i]+'</div>’);
cf[i]=document.getElementById(“theFace”+i).style;
cf[i].top=y-6+30*1.4*Math.sin(i*e*Math.PI/180)+”px”;
cf[i].left=x-6+30*1.4*Math.cos(i*e*Math.PI/180)+”px”;
}
for (i=0; i < n; i++){
document.write(‘<div id=”theDots’+i+'” class=”handsanddotsstyle” style=”background-color:’+dCol+'”></div>’);
cd[i]=document.getElementById(“theDots”+i).style;
cd[i].top=y+30*Math.sin(i*e*Math.PI/180)+”px”;
cd[i].left=x+30*
Math.cos(i*e*Math.PI/180)+”px”;
}
for (i=0; i < h; i++){
document.write(‘<div id=”H’+i+'” class=”handsanddotsstyle” style=”background-color:’+hCol+'”></div>’);
ch[i]=document.getElementById(“H”+i).style;
}
for (i=0; i < m; i++){
document.write(‘<div id=”M’+i+'” class=”handsanddotsstyle” style=”background-color:’+mCol+'”></div>’);
cm[i]=document.getElementById(“M”+i).style;
}
for (i=0; i < s; i++){
document.write(‘<div id=”S’+i+'” class=”handsanddotsstyle” style=”background-color:’+sCol+'”></div>’);
cs[i]=document.getElementById(“S”+i).style;
}

var dsp1=document.getElementById(“amOrPm”).style;
var dsp2=document.getElementById(“theCities”).style;
var dsp3=document.getElementById(“theDate”).style;
var dsp4=document.getElementById(“city”).style;
dsp1.top=y-8+”px”;
dsp1.left=x+6+”px”;
dsp2.top=y-80+”px”;
dsp2.left=x-55+”px”;
dsp3.top=y+55+”px”;
dsp3.left=x-49+”px”;
dsp4.backgroundColor=bCol;
dsp4.color=tCol;

function lcl(z){
zone=z.options[z.selectedIndex].value;
isItLocal=(z.options[0].selected);
plusMinus=(zone.charAt(0) == “-“);
oddMinutes=(zone.indexOf(“.”) != -1);
if (oddMinutes){
getOddMinutes=zone.substring(zone.indexOf(“.”)+1,zone.length)
}
if (plusMinus)
addOddMinutes=(oddMinutes)?parseInt(-getOddMinutes):0;
else
addOddMinutes=(oddMinutes)?parseInt(getOddMinutes):0;
}

function ClockAndAssign(){
hourAdjust=0;
dayAdjust=0;
monthAdjust=0;
now=new Date();
ofst=now.getTimezoneOffset()/60;
var secs = now.getSeconds();
var secOffSet = secs – 15;
if (secs < 15){
secOffSet = secs+45;
}
var sec = Math.PI * (secOffSet/30);
var mins = now.getMinutes();
if (oddMinutes){
mins=mins+addOddMinutes;
}
var minOffSet = mins – 15;
if (mins < 15){
minOffSet = mins+45;
}
var min = Math.PI *
(minOffSet/30);

if (mins<0){
mins+=60;hourAdjust=-1;
}
if (mins>59){
mins-=60;hourAdjust=1;
}
hr=(isItLocal)?now.getHours()+hourAdjust?now.getHours()+parseInt(ofst))+parseInt(zone)+hourAdjust;
hrs=Math.PI*(hr-3)/6+Math.PI*parseInt(now.getMinutes())/360;
if (hr<0){
hr+=24;
dayAdjust=-1;
}
if (hr>23){
hr-=24;
dayAdjust=1;
}
day=now.getDate()+dayAdjust;
if (day<1){
day+=daysInMonth;
monthAdjust=-1;
}
if (day>daysInMonth){
day-=daysInMonth;
monthAdjust=1;
}
month=parseInt(now.getMonth()+1+monthAdjust);
if (month==2){
daysInMonth=28;
}
year=now.getYear();
if (year<2000){
year=year+1900;
}
leapYear=(year%4==0);
if (leapYear&&month==2){
daysInMonth=29;
}
if (month<1){
month+=12;
year–;
}
if (month>12){
month-=12;
year++;
}
todaysDate=day+” “+month+” “+year;
ampm=(hr>11)?”pm”:”am”;

for (i=0;i<s;i++){
cs[i].top=y+(i*hDims)*Math.sin(sec)+addPx;
cs[i].left=x+(i*hDims)*Math.cos(sec)+addPx;
}
for (i=0;i<m;i++){
cm[i].top=y+(i*hDims)*Math.sin(min)+addPx;
cm[i].left=x+(i*hDims)*Math.cos(min)+addPx;
}
for (i=0;i<h;i++){
ch[i].top=y+(i*hDims)*Math.sin(hrs)+addPx;
ch[i].left=x+(i*hDims)*Math.cos(hrs)+addPx;
}
document.getElementById(“amOrPm”).firstChild.data=ampm;
document.getElementById(“theDate”).firstChild.data=todaysDate;
setTimeout(‘ClockAndAssign()’,100);
}
window.onload=ClockAndAssign;
}
//–>

</script>
</div>
</body>
</html>

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@PittimannJul 14.2004 — Hi!

Most likely you have another window.onload= in your existing page or a function being called onload in the body tag. Check your code for such stuff. If you find it, just try placing all these function calls into the body tag like: <body onload="function1();function2();" another body stuff here... >

where you will have to replace function1 and function2 with the names of the functions which need to be called. Important: separate them with semi colons like shown above.

Cheers - Pit
Copy linkTweet thisAlerts:
@zohareauthorJul 14.2004 — i have another script running on the same page, maybe that has an onload entry too.
Copy linkTweet thisAlerts:
@zohareauthorJul 14.2004 — nevermind...got it figured out. You were right.
Copy linkTweet thisAlerts:
@PittimannJul 14.2004 — Hi!

Nice, you got it!

Seems you did NOT get my private message I sent in reply to yours. No prob - you don't need it any more. :p

Cheers - Pit
×

Success!

Help @zohare spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...