Search code examples
javascriptperlcgicountdowntimertemplate-toolkit

Adding count down timer in perl template tool kit


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??


Solution

  • 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)();
    }