Solved

Reload page with current time as URL parameter

Posted on 2014-09-25
2
177 Views
Last Modified: 2014-09-25
I wrote two functions in javascript. The first function displays the current time on the screen. The second takes that time and reloads the page after 5 seconds sending the current value as a URL parameter. Except once I put in the variable the .window.location stops working.

I am not very experienced with javascript and can not seem to figure what I am doing wrong. Here is the code:

<!DOCTYPE html> 
<html> 
<head> 
<script> 
function currentTime() { 
var today=new Date(); 
var Y=today.getFullYear(); 
var M=today.getMonth(); 
var D=today.getDate(); 
var h=today.getHours(); 
var m=today.getMinutes(); 
var s=today.getSeconds(); 
m = checkTime(m); 
s = checkTime(s); 

document.getElementById('clock').innerHTML = Y+ "-"+M+ "-"+D+ " "+h+":"+m+":"+s; 
var t = setTimeout(function(){currentTime()},500); 
} 

function checkTime(i) { 
if (i<10) {i = "0" + i}; // add zero in front of numbers < 10 
return i; 
} 
</script> 

<script> 
<!-- 
function Redirect() 
{ 
window.location.replace = “page.html?var=" Y+ "-"+M+ "-"+D+ " "+h+":"+m+":"+s; 
} 

setTimeout('Redirect()', 5000); 
// 
</script> 
</head> 


<body onload="currentTime()"> 
<div id="clock"></div> 
</body> 
</html> 

Open in new window


Any help would be appreciated.
0
Comment
Question by:serviceco
[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
2 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40344300
<!DOCTYPE html> 
 <html> 
 <head> 
 <script> 

 var today,Y,M,D,h,m,s; 

 function currentTime() { 
 today=new Date(); 
 Y=today.getFullYear(); 
 M=today.getMonth(); 
 D=today.getDate(); 
 h=today.getHours(); 
 m=today.getMinutes(); 
 s=today.getSeconds(); 
 m = checkTime(m); 
 s = checkTime(s); 
 document.getElementById('clock').innerHTML = Y+ "-"+M+ "-"+D+ " "+h+":"+m+":"+s; 
 var t = setTimeout(function(){currentTime()},500); 
 } 

 function checkTime(i) { 
 if (i<10) {i = "0" + i}; // add zero in front of numbers < 10 
 return i; 
 } 
 </script> 

 <script> 
 <!-- 
function Redirect() 
 {
 window.location.replace("page.html?var="+ Y + "-"+M+ "-"+D+ " "+h+":"+m+":"+s); 
 } 

 setTimeout('Redirect()', 5000); 
 // 
 </script> 
 </head> 


 <body onload="currentTime()"> 
 <div id="clock"></div> 
 </body> 
 </html> 

Open in new window

0
 

Author Closing Comment

by:serviceco
ID: 40344430
Thank you!  I understand what I missed. I appreciate the help.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

726 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