/    Sign up×
Community /Pin to ProfileBookmark

Error on page ?

Big thanx to skywalker2208 and ZeroKilled for thier previous advice, that code snippet got me thinking in the right direction ? below is the next problem lol ? this code is the combination of a working countdown script and the newly working (thanks to your help) string splitter. Both scripts have been tested and work fine on thier own but when i try and merge them it all goes horribly wrong lol ?

can anyone see where im going wrong as the original coundown script is far more advanced than my javascript knowledge and my best guesses arent working lol ?

thanx

[CODE]<head>
<title>Countdown</title>
<script type=”text/javascript”>
// time string
var timestr = 0000;

// how many minutes
var mins = 3;

// how many seconds (don’t change this)
var secs = mins * 60;
function countdown() {
setTimeout(‘Decrement()’,1000);
}
function Decrement() {
var minutes = document.getElementById(“minutes”);
var seconds = document.getElementById(“seconds”);
minutes = document.getElementById(“minutes”);
seconds = document.getElementById(“seconds”);
// if less than a minute remaining
if (seconds < 59) {
seconds.value = String(secs).pad(2,0,’left’);
} else {
minutes.value = String(getminutes()).pad(2,0,’left’);
seconds.value = String(getseconds()).pad(2,0,’left’);
}
secs–;
timestr = minutes.concat(seconds);
var start = 0;
var finish = 0;

for(var i = 0; i < timestr.length; i++){
start = (i);
finish = (i+1);
document.getElementById(‘sw1′).innerHTML = “<img border=’0′ src=’clock/” + timestr.substring(start,finish) + “.jpg’>”;
start = (i-1);
finish = (i);
document.getElementById(‘sw2′).innerHTML = “<img border=’0′ src=’clock/” + timestr.substring(start,finish) + “.jpg’>”;
start = (i-2);
finish = (i-1);
document.getElementById(‘sw3′).innerHTML = “<img border=’0′ src=’clock/” + timestr.substring(start,finish) + “.jpg’>”;
start = (i-3);
finish = (i-2);
document.getElementById(‘sw4′).innerHTML = “<img border=’0′ src=’clock/” + timestr.substring(start,finish) + “.jpg’>”;
}

if(secs != -1) setTimeout(‘Decrement()’,1000);
}
function getminutes() {
// minutes is seconds divided by 60, rounded down
mins = Math.floor(secs / 60);
return mins;
}
function getseconds() {
// take mins remaining (as seconds) away from total seconds remaining
return secs-Math.round(mins *60);
}

//length (integer): length of resulting string,
//pad (string): to fill string with,
//type (string): where to pad, default is ‘right’
String.prototype.pad = function(length, pad, type){
if(!String(pad).length || this.length >= length)return this.toString();
var string = this;
switch(type){
case ‘left’:
while(string.length < length)string = pad.toString() + string;
break;

default:
while(string.length < length) string += pad.toString();
}
return string;
}

</script>
</head>
<body onload=”countdown();”>

<table id=’swtab’>
<tr>
<td><p id=’sw4′></p>
</td>
<td><p id=’sw3′></p>
</td>
<td><img border=’0′ src=’clock/colon.jpg’></td>
<td><p id=’sw2′></p>
</td>
<td><p id=’sw1′></p>
</td>
</tr>
</table>

<input id=”minutes” type=”hidden”>
<input id=”seconds” type=”hidden”>

</body>[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@MrNobodyJan 22.2009 — Regarding countdowns, you might want to see this:

http://www.webdeveloper.com/forum/showthread.php?t=200123
×

Success!

Help @scooby545 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.25,
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,
)...