?
Solved

Need Count down java script

Posted on 2011-03-03
6
Medium Priority
?
271 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 27

Accepted Solution

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

Assisted Solution

by:Pratima Pharande
Pratima Pharande earned 400 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

765 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