Page 1 of 1

Experiment! clock (java)

Posted: Wed Dec 16, 2009 7:40 am
by Goofan
Hi i got a java/php script!

I got this clock that uppdates every second... (java)
then im trying to collect the java class updateClock ( ).
I dont know if this is even possible to do but if it is please direct me to the correect path.

Code: Select all

 
<html>
<head>
<title>JavaScript Clock</title>
</head>
<script type="text/javascript">
<!--
function init ( )
{
  timeDisplay = document.createTextNode ( "" );
  document.getElementById("clock").appendChild ( timeDisplay );
}
 
function updateClock ( )
{
  var currentTime = new Date ( );
 
  var currentHours = currentTime.getHours ( );
  var currentMinutes = currentTime.getMinutes ( );
  var currentSeconds = currentTime.getSeconds ( );
 
  // Pad the minutes and seconds with leading zeros, if required
  currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
  currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;
 
  // Choose either "AM" or "PM" as appropriate
  var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";
 
  // Convert the hours component to 12-hour format if needed
  currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;
 
  // Convert an hours component of "0" to "12"
  currentHours = ( currentHours == 0 ) ? 12 : currentHours;
 
  // Compose the string for display
  var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay;
 
  // Update the time display
  document.getElementById("clock").firstChild.nodeValue = currentTimeString;
}
 
// -->
</script>
 
<style type="text/css">
#clock { font-family: Arial, Helvetica, sans-serif; font-size: 0.8em; color: white; background-color: black; border: 2px solid purple; padding: 4px; }
</style>
 
 
 
</head>
<body onload="updateClock(); setInterval('updateClock()', 1000 )">
<div style="clear: both;"> </div>
 
<h1>The JavaScript clock in action</h1>
 
<div style="width: 10em; text-align: center; margin: 20px auto;">
  <span id="clock">updateClock ( )</span>
</div>
<?php
 
 
$clock = new java(updateClock ());
echo $clock;
?>
</body>
</html>
 
error is as followed:
Fatal error: Class 'java' not found in C:\Program Files\wamp\www\mine\thomas\clock.php on line 63

This would make so that the $clock displays the clock of the instance.

Re: Experiment! clock (java)

Posted: Wed Dec 16, 2009 1:26 pm
by McInfo
First, JavaScript (ECMAScript) is not Java.

Second, JavaScript is only a string to PHP, just as plain text or HTML is. It has no dynamic properties--it is not a language--until it arrives at the browser.

Maybe I can suggest an alternative approach if you explain what you want your users to see and do.

Edit: This post was recovered from search engine cache.

Re: Experiment! clock (java)

Posted: Thu Dec 17, 2009 8:52 am
by incubi
There are tricks that can be done but the better way is to write the clock in PHP but
maybe this will help

http://www.javascriptkit.com/javatutors ... lphp.shtml
http://www.smallbizonline.co.uk/php_jav ... iables.php
http://code.activestate.com/recipes/414334/

incubi

Re: Experiment! clock (java)

Posted: Thu Dec 17, 2009 9:02 am
by Goofan
ok im reading :D

Re: Experiment! clock (java)

Posted: Thu Dec 17, 2009 9:15 am
by Goofan
Goofan wrote:Hi i got a java/php script!

I got this clock that uppdates every second... (java)
then im trying to collect the java class updateClock ( ).
I dont know if this is even possible to do but if it is please direct me to the correect path.

Code: Select all

 
<html>
<head>
<title>JavaScript Clock</title>
</head>
<script type="text/javascript">
<!--
function init ( )
{
  timeDisplay = document.createTextNode ( "" );
  document.getElementById("clock").appendChild ( timeDisplay );
}
 
function updateClock ( )
{
  var currentTime = new Date ( );
 
  var currentHours = currentTime.getHours ( );
  var currentMinutes = currentTime.getMinutes ( );
  var currentSeconds = currentTime.getSeconds ( );
 
  // Pad the minutes and seconds with leading zeros, if required
  currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
  currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;
 
  // Choose either "AM" or "PM" as appropriate
  var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";
 
  // Convert the hours component to 12-hour format if needed
  currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;
 
  // Convert an hours component of "0" to "12"
  currentHours = ( currentHours == 0 ) ? 12 : currentHours;
 
  // Compose the string for display
  var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay;
 
  // Update the time display
  document.getElementById("clock").firstChild.nodeValue = currentTimeString;
}
 
// -->
</script>
 
<style type="text/css">
#clock { font-family: Arial, Helvetica, sans-serif; font-size: 0.8em; color: white; background-color: black; border: 2px solid purple; padding: 4px; }
</style>
 
 
 
</head>
<body onload="updateClock(); setInterval('updateClock()', 1000 )">
<div style="clear: both;"> </div>
 
<h1>The JavaScript clock in action</h1>
 
<div style="width: 10em; text-align: center; margin: 20px auto;">
  <span id="clock">updateClock ( )</span>
</div>
<?php
 
 
$clock = new java(updateClock ());
echo $clock;
?>
</body>
</html>
 
error is as followed:
Fatal error: Class 'java' not found in C:\Program Files\wamp\www\mine\thomas\clock.php on line 63

This would make so that the $clock displays the clock of the instance.
JAVA should be JAVASCRIPT :lol:

sorry to all i ment to say something like this:
the string captures the updatable clock so that it is updated "i know this can not be outputted" then when i have collected this i want to see:
if the clock is between 11:30 and 12:00 then update a datatabel to be 1 if not then 0
so if the datatabel is 1 it is to update the table called "money" and that would add an adition 30000.
and if datatabel is 0 then dont update...

this is just the very basics of what it is suposed to do but its the basics that is worth working on right now :D

-hope this makes sens =)

Re: Experiment! clock (java)

Posted: Thu Dec 17, 2009 9:28 am
by incubi
You need to update a database table field based on a time window?
Is there a reason you can't use a php time function for this?

incubi

Re: Experiment! clock (java)

Posted: Thu Dec 17, 2009 9:31 am
by Goofan
ohh yea i forgot that :D thanks
dont know the answer to this one?:
viewtopic.php?f=1&t=110344

Re: Experiment! clock (java)

Posted: Thu Dec 17, 2009 10:06 am
by incubi
Well if I was trying to disable a submit button for a time in php it may not be the best way but I would put the submit button html in a php var and only show it when I wanted. for example

Code: Select all

 
 
<?php
$show = 0;
if($show)
    $button = '<input type="image" src="submit.gif" value="Submit" alt="Submit">';
else    
    $button ="";
 
print '<br><form action="#" method="get"><input type="text" name="text"><BR>'.$button.'</form>';
 
?>
 

Re: Experiment! clock (java)

Posted: Thu Dec 17, 2009 11:09 am
by Goofan
thanks :d GREAT idé. didnt think of it like that :D

Re: Experiment! clock (java)

Posted: Thu Dec 17, 2009 2:18 pm
by Goofan
can I make so that it will be disabled for 3 seconds?

Re: Experiment! clock (java)

Posted: Thu Dec 17, 2009 2:38 pm
by incubi
You can make it for any time window you like using the time functions in php

http://php.net/manual/en/function.time.php

incubi