0

I have checked some possibilities for adding a count down timer in a cgi page.But i couldn't find anything helpful.

I have written the file to add countdown timer, 'Timer.js' and is calling from the html file 'timer.html'.My problem is i want to pass a value from my cgi template tool kit file to timer.html file as the starting of the timer.

my template file is edit.html.tmpl

i have a table in this template file, and in the 3rd column i want to add the count down timer.just like below, i called the counter there by hardcording the starting value in the template file :

<td align="center">
[% PROCESS bug/timer.html %]
</td>

I want to pass the below value to the timer.html file as the starting of the timer.

<td align="center">
      <input name="estimated_time" id="estimated_time"
             value="[% PROCESS formattimeunit
                               time_unit=bug.estimated_time %]"
             size="6" maxlength="6">
      <input type = "Hidden" name="estimate_time" id="estimate_time" value="[% bug.estimated_time %]" size="6" maxlength="6">
    </td>

How can i achieve this????can anyone please help me in doing this??

Jenifer_justin
  • 167
  • 1
  • 20
  • So you need to get a value from your `[% PROCESS bug/timer.html %]` call into your `Timer.js` JavaScript? How is the timer JavaScript started? Couldn't you just set a value in a ` – mu is too short Jun 11 '13 at 02:53
  • i want to get the value bug.estimated_time from the tmpl file to the timer as the starting value . – Jenifer_justin Jun 11 '13 at 03:09
  • in the place of 60, i want the value. – Jenifer_justin Jun 11 '13 at 03:10

1 Answers1

1

If you can put your JavaScript in that template then you could do it the easy way:

<script type="text/javascript">
    window.onload = CreateTimer("timer", [% bug.estimated_time %]);
</script>

If the CreateTimer call is elsewhere, then you could set a value in your bug/timer.html template:

<script type="text/javascript">
    window.timer_time = [% bug.estimated_time %];
</script>

and then use that value later:

<script type="text/javascript">
    window.onload = CreateTimer("timer", window.timer_time);
</script>

That assumes that the window.onload script will occur after the window.timer_time script, if that's not the case then you'll have to force the issue with something like this:

window.onload = function() {
    CreateTimer('timer', window.timer_time)();
}
mu is too short
  • 426,620
  • 70
  • 833
  • 800
  • Thank you...it is working fine now.... i have one doubt too....i don't want to reset the timer every time the window load.once the timer get started by getting the bug.estimated_time value, it will count down till becomes 0 without any stop. what can i do for that?? – Jenifer_justin Jun 11 '13 at 03:57
  • I suppose you could store the timer value in a cookie and then get `CreateTimer` to check the cookie and fall back to its second argument. – mu is too short Jun 11 '13 at 04:03