Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2014-09-30 06:54:28

alivato
Member
Registered: 2011-03-31
Posts: 151

Timer does not work

Why this code does not work?

Page

<txp:output_form form="timer" />

Form timer

<div class="topbox">
<div id="ny_date"></div>
</div>

Other form with code

<script LANGUAGE="javascript">  
function tNY()  
{  
  var today = new Date();  
  var BigDay = new Date("January 01, 2015");  
  var timeLeft = (BigDay.getTime() - today.getTime());  
  var e_daysLeft = timeLeft / 86400000;  
  var daysLeft = Math.floor(e_daysLeft);  
  var e_hrsLeft = (e_daysLeft - daysLeft)*24;  
  var hrsLeft = Math.floor(e_hrsLeft);  
  var e_minsLeft = (e_hrsLeft - hrsLeft)*60;  
  var minsLeft = Math.floor(e_minsLeft);  
  var seksLeft = Math.floor((e_minsLeft - minsLeft)*60);  
  if (BigDay.getTime() > today.getTime() )  
  document.getElementById("ny_date").innerHTML = '<div class="bnyy">Left until the New Year<br /></div> <div class="bny"><b>'+daysLeft+'</b> days<b>'+hrsLeft+'</b> h. <b>'+minsLeft+'</b> min. <b>'+seksLeft+'</b> sec.</div>'
  else  
  document.getElementById("ny_date").innerHTML = '<div class="nyy">Congr...</div> <div class="ny">NY!!!</div>'  
}  
setInterval("tNY()", 50)  
</script>

Last edited by alivato (2014-09-30 06:55:48)

Offline

#2 2014-09-30 07:13:09

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,007
Website GitHub Mastodon Twitter

Re: Timer does not work

Hi alivato,

There is a countdown plugin which works seamlessly and it might be of help


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#3 2014-09-30 08:05:36

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Re: Timer does not work

colak wrote #284329:

There is a countdown plugin

Umm, do you mean smd_countdown ? Regardless, in this instance it might not be the best solution, although you can use it to seed a Javascript timer, you still need to actually write the Javascript bit, which is what the problem is here.

alavito, in what way does the code not work? Any errors in the browser’s debug console?


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#4 2014-09-30 08:21:32

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,007
Website GitHub Mastodon Twitter

Re: Timer does not work

Bloke wrote #284331:

Umm, do you mean smd_countdown ?

Errrh… That’s what I meant:)


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

Board footer

Powered by FluxBB