Solved

Need Count down java script

Posted on 2011-03-03
6
251 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

828 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