function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jaanvivekjaanvivek 

How to Show Custom timer using Java script on VF page

I need to show custom timer on a VF page.

 

I have 6 questions to be answered on VF page so i want to show timer in form "0:00".

 

I want to give only 10 minutes for a page after 10 minutesthe timer should stop and it should be in "0:10" form

 

I have tried some java script but not successed.

 

 

could any one suggest something.

 

 

Thanks

JaanVivek

 

jaanvivekjaanvivek

I have tried below one.

 

<output name="x" id="txt"/>
<script>
var num=0.100;
var c=num.toFixed(2);
var t;
var myVar;
var myVarOne;
function myFunction()
{
t=setInterval(function(){myTimer()},1000);
}

function myTimer()
{
  document.getElementById('txt').value=c;
   var z= 0.010;
   var m=z.toFixed(2);
   c=(c-m).toFixed(2);

   if(c==0.05)
   {
     
     myVar=setTimeout(function(){alert("Only 5 minutes are left")},1000);  

   }
else if(c==-0.01)
{

   clearInterval(t);
   myVarOne=setTimeout(function(){alert("Sorry your time is over")},1000);  
  

  

}



   

  

 
}

</script>
<body onload="myFunction()"></body>

  It's showing timer in "0.10" format.

 

 

Thanks,

JaanVivek

<output name="x" id="txt"/>
<script>
var num=0.100;
var c=num.toFixed(2);
var t;
var myVar;
var myVarOne;
function myFunction()
{
t=setInterval(function(){myTimer()},1000);
}

function myTimer()
{
  document.getElementById('txt').value=c;
   var z= 0.010;
   var m=z.toFixed(2);
   c=(c-m).toFixed(2);

   if(c==0.05)
   {
     
     myVar=setTimeout(function(){alert("Only 5 minutes are left")},1000);  

   }
else if(c==-0.01)
{

   clearInterval(t);
   myVarOne=setTimeout(function(){alert("Sorry your time is over")},1000);  
 

 

}



   

 

 
}

</script>
<body onload="myFunction()"></body>