• Venkat Sainath
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
Hello Guys,
I am working on Countdown timer, On clicking Save, I am fetching the time from Time__c field and on clicking save the timer will start counting down and once it becomes 0, a pop up will come. If I enter 10 in Time__c field then countdown should start from 10.
<apex:page standardController="Timer_Alert__c">
 <apex:form >
   <apex:pageblock >
      <apex:pageMessages id="showmsg"></apex:pageMessages>
         <apex:panelGrid columns="2">
           Timer_Alert__c Time: <apex:inputText value="{!Timer_Alert__c.Time__c}"/>
           <apex:commandButton value="Save" action="{!save}" oncomplete="timer()" style="width:90px" rerender="showmsg"/>
         </apex:panelGrid>
                     <div align="center" draggable="false" >
         <script>
    function startTimer(duration, display) {
        var start = Date.now(),
            diff,
            minutes,
            seconds;
        function timer() {
            diff = duration - (((Date.now() - start) / 1000) | 0);
            
            minutes = (diff / 60) | 0;
            seconds = (diff % 60) | 0;
            
            minutes = minutes < 10 ? "0" + minutes : minutes;
            seconds = seconds < 10 ? "0" + seconds : seconds;
            
            display.textContent = minutes + ":" + seconds; 
            
            if (diff <= 0) {
                start = Date.now() + 1000;
            }
            if(diff==0){
                alert('STOP!!!');
                clearInterval(interval);
            }
        };
        timer();
        var interval = setInterval(timer, 1000);
    }
    
    window.onload = function () {
        var fiveMinutes = 60 * {!Timer_Alert__c.Time__c},
            display = document.querySelector('#time');
        startTimer(fiveMinutes, display);
    };
    </script>
    <style>
        h1 {
        font-size: 40px;
        text-align: center;
        background-color: orange;
        }
    </style>
    
    <style>
        h1 {
            font-size: 40px;
            text-align: center;
            background-color: orange;
        }
    </style>

            </div>
    </apex:pageblock>
 </apex:form>
</apex:page>


I have created the following VF Page but its not working, can anyone help me with the same.