How to create a timer item in Oracle Apex

by | Oct 29, 2020

In this blog, I’ll walk you through how to create a timer item in your Oracle Apex application.

In this example, I am creating a timer clock that starts from 00:00 that counts till the page is active. You can make modifications to your timer item to match your scenario.

Here is how I created it:

  • Create a display only item
  • Create a dynamic action which is triggered on page load.

  • Create a True action that execute JavaScript code and paste the following code in it.
  • Note: ‘P5_TIMER’ is the name of your display only item.

var timeoutHandle;
function countdown(minutes) {
   var seconds = 0;
   var mins = minutes
   function tick() {
       var current_minutes = mins
       seconds++;
       var c = current_minutes.toString() + ":" 
               + (seconds < 10 ? "0" : "") 
               + String(seconds);
       apex.item('P5_TIMER').setValue(c);
       if( seconds < 60 ) {
           timeoutHandle=setTimeout(tick, 1000);
       } else {
           setTimeout(function () { countdown(mins + 1); }, 1000);
       }
   }
   tick();
}
countdown(0);

The Timer item will look like the below image on the UI.

This image has an empty alt attribute; its file name is image-edited.png

Thanks

Salin

Salin is the newest member of our dev team and is currently learning a bunch of new tech and skills.  If you’re into learning about Apex, you should read about creating a visually stunning application using Apex, or check out any of her other blogs.

0 Comments
Submit a Comment

Your email address will not be published. Required fields are marked *