Solved

Need Count down java script

Posted on 2011-03-03
6
238 Views
Last Modified: 2012-05-11
Hello,

i need java script for count down.

which get value from variable $stime; in minutes

and start count decreasing oder in minutes and seconds


thanks
0
Comment
Question by:savsofts
6 Comments
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 400 total points
ID: 35025159
0
 
LVL 39

Assisted Solution

by:Pratima Pharande
Pratima Pharande earned 100 total points
ID: 35025287
try this hope helps
<html>
  <head>
    <title>count down.</title>
  <script>
    var today  = new Date();
    var twoHrs = new Date(today.getTime() + 7200000);

    function showHumanDifference()
    {
      var now  = new Date()
      var diff = twoHrs.getTime() - now.getTime();

      if (diff < 0)
      {
        timeOut();
      }

      var hours   = Math.floor(diff / 3600000) ;
      diff       -= (hours * 3600000); // take away hours in milliseconds

      var minutes = Math.floor(diff / 60000);
      diff       -= minutes * 60000; // take away minutes equivalent in milliseconds

      var seconds = Math.floor(diff / 1000) // - (hours * 360000) - (minutes * 60) * 1000 ;

     //document.write(hours + ":" + Math.floor(minutes) + ":" + seconds + " until sessions times out");
document.getElementById("Text1").value = hours + ":" + Math.floor(minutes) + ":" + seconds 
      setTimeout("showHumanDifference()", 100)
    }

    function timeOut()
    {
      if (confirm("Session time out. Do you want to logg back in?"))
      {
        location.href = "home.html"
      }
      else
      {
        self.close();
      }
    }

  </script>
  </head>
  <body onload="showHumanDifference()">
<INPUT type="text" ID="Text1" NAME="Text1" >
  </body>
</html>

Open in new window

0
 
LVL 3

Expert Comment

by:pius_babbun
ID: 35025585
Check if this Idea works out for your requirement. Hope it helps you.
<form name="counter">
<input type="text" size="8" name="starttime">
<input type="text" size="8" name="d2">
<input type="button" size="8" name="Start" value="Start" onclick="javascript:display()" >
</form> 

<script> 
<!-- 
// 

 var milisec=0 
 var seconds=  document.counter.starttime.value; 
 document.counter.d2.value= document.counter.d1.value;

function display()
{ 
clearTimeout();
document.counter.reset();
 if (milisec<=0)
 { 
    milisec=9 
    seconds-=1 
 } 
 if (seconds<=-1){ 
    milisec=0 
    seconds+=1 
 } 
 else 
    milisec-=1 
    document.counter.d2.value=seconds+"."+milisec 
    setTimeout("display()",100) 
	
} 
--> 
</script>

Open in new window

0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:savsofts
ID: 35025874
i have variable in <body> section script run in <head> section>

I want script take variable value from <body> section.
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 35025962
you can take it by using
document.getElementById("Text1").value
0
 
LVL 82

Expert Comment

by:leakim971
ID: 35026418
Check this plugin too : http://keith-wood.name/countdown.html
You can specify the format and the layout, click on the tabs to see
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now