View Full Version : Alarm Clock


SUPER RP06
01-16-2005, 09:53 PM
Firstly, insert this code between the <HEAD> tags.

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin


function clock() {
if (!document.layers && !document.all) return;
var hex = new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F")
var ticktock = new Date();
var year = ticktock.getFullYear();
var utime = ticktock.getTime();
var hours = ticktock.getHours();
var minutes = ticktock.getMinutes();
var seconds = ticktock.getSeconds();

var milliseconds = (utime*1000).toString().substring(10,13);


if (hours <= 9) hours = "0" + hours;
if (minutes <= 9) minutes = "0" + minutes;
if (seconds <= 9) seconds = "0" + seconds

document.clock.hr.value = hours
document.clock.min.value = minutes
document.clock.sec.value = seconds
document.clock.ms.value = milliseconds
setTimeout("clock()", 1);
}

function alarm() {

var hr = document.arlm.h.value;
var mins = document.arlm.mts.value;

if ((document.clock.hr.value == hr) &&
(document.clock.min.value == mins)) {
alert("ALARM!!!!!!!!!!");
return false}

if (hr == '') {alert('Empty Hour Field!'); return false}
if (mins == '') {alert('Empty Minute Field!'); return false}

if (hr.length == 1) {document.arlm.h.value = '0' + hr}
if (mins.length == 1) {document.arlm.mts.value = '0' + min}
if (hr.length > 2) {alert('Hour Typo!'); return false}
if (mins.length > 2) {alert('Minute Typo!'); return false}
setTimeout("alarm()", 1);}

// End -->
</script>

Then, place this code between the <BODY> tags
<table border="1">
<FORM NAME="clock" enctype="text/plain" onSubmit="0">
<tr>
<td>
Standard<BR>
<input type="text" NAME="hr" SIZE="1" VALUE="">:<input type="text" NAME="min" SIZE="1" VALUE="">:<input type="text" NAME="sec" SIZE="1" VALUE="">.<input type="text" NAME="ms" SIZE="1" VALUE="">
</td>

</tr>
</FORM>
<tr>
<form name="arlm">
<td>
Standard<BR>
Alarm Time<BR>
<input type="text" size="1" name="h" onFocus="select()">:<input type="text" size="1" name="mts" onFocus="select()"><BR>
<input type="button" size="1" value="Set" onClick="alarm()">
<input type="button" size="1" value="Reset" onClick="reset()">
</td>
</form>
</tr>
</table>

Finally, place this in the <BODY> tag itself.
<BODY onLoad="clock()">

Please note that the clock is in the 24-hour time format. (ex: 1:00am = 01:00, 4:00pm = 16:00) (No AM/PM). Also this clock has seconds and milliseconds!