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.
Thanks
Salin