Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Need Count down java script

Posted on 2011-03-03
6
Medium Priority
?
275 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
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 look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

604 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