Free Steam Games
Loading...

Membuat Alarm Dengan Java Script

|

Bila anda sering blogging di internet dan lupa waktu anda bisa memanfaatkan Script ini untuk membuat alarm dengan musik wav anda sendiri.
Silahkan Copy Semua script di bawah ini ke notepad dan beri nama terserah pokoknya formatnya .html, untuk menjalankan script di bawah ini satukan file html dengan file .wav.



<html>

<head>
<title>Alarm</title>

<script language="JavaScript" type="text/javascript">

<!--
var sound = "alarm.wav"; // gunakan nama file wav yang berbeda jika ingin menambahkan musik saat alarm menyala, calvin-alexander.blogspot.com


function sivamtime() {
now=new Date();
hour=now.getHours();
min=now.getMinutes();
sec=now.getSeconds();

if (min<=9) {
min="0"+min;
}
if (sec<=9) {
sec="0"+sec;
}
if (hour>12) {
hour=hour-12;
add="pm";
}
else {
hour=hour;
add="am";
}
if (hour==12) {
add="pm";
}
if (hour==00) {
hour="12";
}

document.hours.clock.value = (hour<=9) ? "0"+hour : hour;
document.minutes.clock.value = min;
document.seconds.clock.value = sec;
document.ampm.clock.value= add;
setTimeout("sivamtime()", 1000);

}

function alarm() {
note = document.arlm.message.value;
if (note == '') {note = 'ALARM!!';}

hrs = document.arlm.hr.value;
min = document.arlm.mts.value;
apm = document.arlm.am_pm.value;

if ((document.hours.clock.value == hrs) &&
(document.minutes.clock.value == min) &&
(document.ampm.clock.value == apm) &&
(document.arlm.music.checked == true)) {
musicwin=window.open("","","width=200,height=50")
if (navigator.appName=="Microsoft Internet Explorer")
musicwin.document.write("<bgsound src=" + sound + " loop='infinite'>" + note)
else
musicwin.document.write("<embed src=" + sound + " hidden='true' border='0' width='20' height='20' autostart='true' loop='true'>" + note)
musicwin.document.close(); return false; }

if ((document.hours.clock.value == hrs) &&
(document.minutes.clock.value == min) &&
(document.ampm.clock.value == apm) &&
(document.arlm.music.checked == false)) {
alert(note); return false; }

if (hrs == '') {alert('The Hour field is empty'); return false}
if (min == '') {alert('The Minute field is empty'); return false}
if (apm == '') {alert('The am/pm field is empty'); return false}

if (hrs.length == 1) {document.arlm.hr.value = '0' + hrs}
if (min.length == 1) {document.arlm.mts.value = '0' + min}
if (hrs.length > 2) {alert('The Hour is wrongly typed.'); return false}
if (min.length > 2) {alert('The Minute is wrongly typed.'); return false}
if (apm != 'am' && apm != 'pm' ) {alert('The am/pm is wrongly typed.'); return false}

setTimeout("alarm()", 1000);}

//-->
</script>
</head>

<body>

<body onLoad="sivamtime()">

<table border="0" align="center" bgcolor="#c0c0c0" cellspacing="0" cellpadding="2" width="170">
<tr>
<td colspan="4">
<font size="1" face="verdana, arial, helvetica, ms sans serif">
<b>Current Time</b>
</font>
</td>
</tr>
<tr>
<td>
<form name="hours">
<p><input type="text" size="2" name="clock"></p>
</form>
</td>
<td>
<form name="minutes">
<p><input type="text" size="2" name="clock" /></p>
</form>
</td>
<td>
<form name="seconds">
<p><input type="text" size="2" name="clock" /></p>
</form>
</td>
<td>
<form name="ampm">
<p><input type="text" size="2" name="clock" /></p>
</form>
</td>
</tr>
</table>


<table border="0" align="center" bgcolor="#c0c0c0" cellspacing="0" cellpadding="2" width="170">
<tr>
<td colspan="3">
<form name="arlm">
<font size="1" face="verdana, arial, helvetica, ms sans serif">
<b>Alarm Time</b>
</font>
</td>
</tr>
<tr align="center">
<td>
<font size="1" face="verdana, arial, helvetica, ms sans serif">
&nbsp;Hour&nbsp;
</font>
</td>
<td>
<font size="1" face="verdana, arial, helvetica, ms sans serif">
&nbsp;&nbsp;Minute
</font>
</td>
<td>
<font size="1" face="verdana, arial, helvetica, ms sans serif">
&nbsp;am/pm
</font>
</td>
</tr>
<tr align="center">
<td>
<input type="text" size="2" name="hr" onFocus="select()" value="00" />
</td>
<td>
&nbsp;&nbsp;<input type="text" size="2" name="mts" onFocus="select()" value="00" />
</td>
<td>
&nbsp;<input type="text" size="2" name="am_pm" onFocus="select()" value="am" />
</td>
</tr>
<tr align="center">
<td colspan="3">
<font size="1" face="verdana, arial, helvetica, ms sans serif">
Message
</font>
</td>
</tr>
<tr align="center">
<td colspan="3">
<input type="text" size="15" name="message" />
</td>
</tr>
<tr align="center">
<td colspan="3">
<input type="checkbox" name="music">
<font size="1" face="verdana, arial, helvetica, ms sans serif">Play music?</font>
</td>
</tr>
<tr>
<td align="center" colspan="3">
<input type="button" size="2" value="Set Alarm" onClick="alarm()" />
</td>
</tr>
<tr>
<td align="center" colspan="3">
<input type="button" size="2" value="Reset" onClick="reset()" />
</td>
</tr>
</table>
</form>


</body>
</html>


Gimana Hasilnya ? Woow !
Hasilnya bisa download here. (Sudah include file Wav nya)

3 comments:

zifoe said...

waaah.. tambah kreatif niiih.. salut deh.. terus berkreasi yach... Semangat....!!!!!!

Azwar said...

mantap nie postingannya.. cobah ah

Onal said...

Bisa di kasih penjelasannya...

Post a Comment

Related Posts with Thumbnails