0
<!doctype html>
<!-- Name:Thomas Smith
     Email:tsmith27@my.athens.edu
     Student No.00048668 -->
<!-- ============================================================== -->
<html>
 <head>
 <meta charset="utf-8">
   <title>Time Remaining</title>
   <body>
   <h1 style="text-align:left">How Much Time Until?</h1>
   <br>
   <p>Enter the date: <input type="text" id="endBox" size=16 value=''></p>
   <br>
   <br>
   <hr>
   <input type="button" value="Find Out" style="width:130px;" onclick="javascript:TimeUntil();"/>
   <div id="outputDiv"></div>
      <script type="text/javascript" src="time.js"></script>
      <script type="text/javascript">
function TimeUntil()
{document.getElementById('endBox').value);
  var seconds = SecondsUntil('endBox');
  var time = SecondsToString(answer);

  return time;
}
function SecondsToString(seconds)
{
  var days = Math.floor(seconds / (24*60*60));
  seconds = seconds - days*(24*60*60);
  var hours = Math.floor(seconds / (60*60));
  seconds = seconds - hours*(60*60);
  var minutes = Math.floor(seconds / 60);
  seconds = seconds - minutes*60;

  var answer = days + ' days, ' + hours + ' hours, ' + minutes + ' minutes, ' +
         seconds + ' seconds';
}
function SecondsUntil(endBox)
{
  var goalDate = new Date(endBox);
  var current = new Date();
  var diff = Math.floor((goalDate - current)/1000);
 document.getElementById('outputDiv')innerHTML = "Time left is " + diff;   
  }
</script>
</body>
</html>

Edited by Thomas_31: Can anyone help, I have to turn this in Monday. I've been given a solution by a friend on another site but it's more complicated than what is here and I know my Professor would know it wasn't my work. I just need to know what to do with this code to make

3
Contributors
2
Replies
18
Views
1 Year
Discussion Span
Last Post by 2teez
1

Hi Thomas_31,

There are numbers of errors in your script. Bu the obvious one in which you presently batteling with occurs on line 22 of the OP.
You are taking the vaule of text in the textbox you provided, but you are not assigning it to any variable, hence it taken it into void like. So you probably want to assign that to a variable like so: var myValue = document.getElementById('endBox').value; and then pass that variable to your function SecondsUntil like so var seconds = SecondsUntil(myValue); and not what you are presently doiing.

Secondly, you will not also get display like you wanted because instead of doing this document.getElementById('outputDiv').innerHTML = "Time left is " + diff; you are doing this document.getElementById('outputDiv')innerHTML = "Time left is " + diff; Check line 45. It is .innerHTML, you missed the ..

Lastly, what is the scope of your variable answer used in line 24?

Please check these and some other design issues.

Hope this helps.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.