Results 1 to 2 of 2

Thread: JavaSript Alarm question

  1. #1
    Join Date
    Sep 2005
    Location
    Connecticut
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JavaSript Alarm question

    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

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <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);
    }
    </script>
    <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>
    </form>
    Last edited by Twey; 10-12-2005 at 05:11 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •