View Full Version : JavaSript Alarm question

10-12-2005, 02:51 AM
Its me, again! Sigh, ive had to ask questions every day now that i've forayed into the wonderful world of JavaScript. I was wondering how to create a script that creates a javascript message after a number of miliseconds defined in a text box, and a message defined in another text box. It will create a kind of alarm, where after a user-defined amount of time, a message that has also been defined by them would pop up.
Thanks for any help :)

10-12-2005, 04:30 PM
<script type="text/javascript">
function fireMessage(form) {
var time = parseInt(form.elements['time'].value);
var message = form.elements['msg'].value;
if(time !== time) time = 0; // if time isn't a valid number, set it to 0
else window.setTimeout("window.alert(message)", time);
<form onsubmit="fireMessage(this);return false;">
Time: <input type="text" id="time" size="6"/><br/>
Message: <input type="text" id="message"/><br/>
<button onclick="fireMessage(this.form);">Start</button>