We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

How can I create a timer that can be displayed in my form?

hidrau
hidrau asked
on
Medium Priority
297 Views
Last Modified: 2012-05-11
Hello guys

I'd like to have a timer that could be displayed in my form, this timer will be from 1 minute to 0

I will use this to show the user how many minutes it has before the page be reload.

is there any way to do this in Javascript or Jquery?

thanks
Comment
Watch Question

Author

Commented:
Hi, I did this code:


but I am not being able to start the code
<script type="application/javascript">
  var c=60;
  var t;
  var time_is_on=0;
				
  function contagem()
  {
    document.getElementById("textfield").value=c;
    c=c-1;
    t=setTimeout("contagem()",1000);			
  }
		
  function start_time()
  {
    if (!time_is_on)
     {
       time_is_on=1;
       contagem();
     }
   }
		
  start_time();
  setTimeout("location.href='index.asp?f=S'", 1 * 60 * 1000);
</script>

Open in new window

Roman GhermanSenior Software Engineer
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
thanks very much

Author

Commented:
just one thing,

if I have 420 seconds that is 7 minutes, how can I format my seconds in minutes and seconds lapsed?

leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
For example :
var secondsLeft = 420; 
	window.onload = setInterval("updateTimer()", 1000);
	function updateTimer() {
		var h = document.createElement("h3");
                var s = secondsLeft%60;
                var m = parseInt(secondsLeft/60);
		h.innerHTML = m + "min" + s + "s";
		if(secondsLeft--<0) {
			location.href = "http://www.experts-exchange.com/Programming/Languages/Scripting/JScript/Q_26985174.html";
		}
		else {
			document.getElementById("timer").innerHTML = ""; 
			document.getElementById("timer").appendChild(h); 
		}
	}

Open in new window

leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Thanks for the points!
Roman GhermanSenior Software Engineer

Commented:
nice - my solution is the assisted one?
sorry but @leakim971 and your's solution is not working because of:  <script type="application/javascript"> - which is not correct.



here is a solution with minutes: http://javascript.internet.com/time-date/countdown-timer-2.html
leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
@roma1123 is right on IE it don't work, just remove the type attribute or replace it with : text/javascript
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.