Solved

Need Count down java script

Posted on 2011-03-03
6
246 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

773 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