/    Sign up×
Community /Pin to ProfileBookmark

The problem that I am having is that I want to have a page that displays a clock by calling a .js file function. This is shown below:

Actual page:

[code]
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.1//EN”
“http://www.w3.org/TR/xhtml11/DTD/
xhtml11.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en” >
<?php
session_start();
include “../../../u0000700/wes_ica_08_09/wes_ica.inc”;
?>
<head>
<link rel=”stylesheet” type=”text/css” href=”wes_ica.css” />
<script type=”text/javascript” src=”wes_ica.js”></script>
<script type=”text/javascript” src=”../../../u0000700/wes_ica_08_09/wes_ica.js”></script>
<title>Clock</title>
</head>

<body onload=”globalclock()”>
<form>
<p><object height=”200″ width=”200″ type=”image/svg+xml” data=”wes_ica.svg”>
</object></p>
<p><input type=”text” id=”globalclock” /></p>
</form>
[/code]

The code it calls in the “../../../u0000700/wes_ica_08_09/wes_ica.js” file is :

[code]
function globalclock() {
var clocktime = new Date();
clocktime.setMinutes(clocktime.getMinutes()+cities[city][1]);
maketimedisp(clocktime);
timestring=””;
timestring+=cities[city][0];
timestring+=” – “;

switch (dow) {
case “n”:
timestring=timestring;
break;
case “s”:
timestring=timestring+startdayofweek.substring(0,3)+” “;
break;
case “f”:
timestring=timestring+startdayofweek+” “;
break;
default:
timestring=”Error”;
}
switch (cdate) {
case “n”:
break;
case “a”:
case “b”:
case “c”:
case “d”:
case “f”:
case “g”:
case “h”:
case “i”:
case “k”:
case “l”:
case “m”:
case “o”:
timestring=timestring+startday;
break;
case “j”:
case “e”:
case “p”:
if (startday>9) {
timestring=timestring+startday
} else{
timestring=timestring+”0″+startday
}
break;
default:
timestring=”Error”;
}
if (startday<20) {
de=dayending[startday];
} else {
de=dayending[startday&#37;10];
}
switch (cdate) {
case “n”:
case “b”:
case “d”:
case “e”:
case “g”:
case “i”:
case “j”:
case “l”:
case “o”:
case “p”:
break;
case “a”:
case “c”:
case “f”:
case “h”:
case “k”:
case “m”:
timestring=timestring+de;
break;
default:
timestring=”Error”;
}
switch (cdate) {
case “n”:
break;
case “a”:
case “b”:
case “f”:
case “g”:
case “k”:
case “l”:
timestring=timestring+” “+startmonth+” ”
break;
case “c”:
case “d”:
case “h”:
case “i”:
case “m”:
case “o”:
timestring=timestring+” “+startmonth.substring(0,3)+” ”
break;
case “e”:
case “j”:
if (start31month>9) {
cmonth=start31month
} else {
cmonth=”0″+start31month;
}
timestring=timestring+”/”+cmonth+”/”
break;
case “p”:
if (start31month>9) {
cmonth=start31month
} else {
cmonth=”0″+start31month;
}
timestring=timestring+”/”+cmonth+” ”
break;
default:
timestring=”Error”;
}
syear=startyear;
switch (cdate) {
case “n”:
case “k”:
case “l”:
case “m”:
case “o”:
case “p”:
break;
case “a”:
case “b”:
case “c”:
case “d”:
case “e”:
timestring=timestring+syear+” “;
break;
case “f”:
case “g”:
case “h”:
case “i”:
case “j”:
yearstring=””+syear;
tempyear=yearstring.match(/..$/);
timestring=timestring+tempyear+” “;
break;
default:
timestring=”Error”;
}
switch (ctime) {
case “n”:
break;
case “a”:
case “b”:
case “c”:
case “d”:
timestring=timestring+starthour;
break;
case “e”:
case “f”:
timestring=timestring+start24hour;
break;
default:
timestring=”Error”;
}
switch (ctime) {
case “n”:
break;
case “a”:
case “b”:
case “c”:
case “d”:
case “e”:
case “f”:
if (startminute<10) {
sminute=”:0″+startminute;
} else {
sminute=”:”+startminute;
}
timestring=timestring+sminute;
break;
default:
timestring=”Error”
}
switch (ctime) {
case “n”:
case “b”:
case “d”:
case “f”:
break;
case “a”:
case “c”:
case “e”:
if (startsecond<10) {
ssecond=”:0″+startsecond;
} else {
ssecond=”:”+startsecond;
}
timestring=timestring+ssecond;
break;
default:
timestring=”Error”
}
switch (ctime) {
case “n”:
case “c”:
case “d”:
case “e”:
case “f”:
break;
case “a”:
case “b”:
timestring=timestring+” “+startmeridian;break;
default:
timestring=”Error”;
}
document.getElementById(“globalclock”).value = timestring;
id = setTimeout(“globalclock()”, 1000);
}
[/code]

The problem that I am having is that I have to declare 3 variables in the text/javascript” src=”wes_ica.js file.
These variables are:

dow “f” or “s”
cdate one from “a” to “p” except “n”
ctime one from “a” to “f”

These variables are then used to make the globalclock function work. I just do not know how to lay this out on the page. Things such as the header etc. Do they have to be in a function?

The layout that I have so far is this:

var dow = (“f”,”s”);
var cdate = (“a”,”b”,”c”,”d”,”e”,”f”,”g”,”h”,”i”,”j”,”k”,”l”,”m”,”o”,”p”);
var ctime = (“a”,”b”,”c”,”d”,”e”,”f”);

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@omnicityAug 04.2009 — If you cannot place this section into the external JS file directly, then you need to place it within

<script>

tags.

I also suspect that you want square brackets there, or possibly curly brackets. Round ones are basically only used for function definitions.
×

Success!

Help @El_Dudereno 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 4.24,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...