logo
g Text Version
Beauty & Self
Books & Music
Career
Computers
Education
Family
Food & Wine
Health & Fitness
Hobbies & Crafts
Home & Garden
Money
News & Politics
Relationships
Religion & Spirituality
Sports
Travel & Culture
TV & Movies

dailyclick
Bored? Games!
Nutrition
Postcards
Take a Quiz
Rate My Photo

new
Action Movies
Bible Basics
Houseplants
Romance Movies
Creativity
Family Travel
Southwest USA


dailyclick
All times in EST

Full Schedule
g
g JavaScript / Java Site

BellaOnline's JavaScript / Java Editor

g

Hearing Dog Training Tool setTimeout()

Guest Author - Julie L Baumler

In a previous article, I started the iterative development of a small JavaScript program to assist in training a dog to do sound alerts. So far, the program, which you can view here, includes a set alarm button which, when pressed, pops up an alert stating that the alarm has gone off (although the audible alarm is not yet configured.) As the next step, we are going to actually set the wait between pressing the "set alarm" button and the alarm, such as it is, going off.

JavaScript and the Document Object Model (DOM), have a bunch of event handlers to wait for something to happen (i.e. onClick, onMouseOver, ...); however in this case, we want to wait for an amount of time to pass, the DOM provides a method to do this as well setTimeout(). setTimeout() requires two arguments, a piece of code or a function to run and the time to wait in milliseconds before running it. set_timeout() can also take an optional third option designating the scripting language used - JavaScript, JScript, or VBScript (this is part of the DOM, not JavaScript, remember.)

Our new code looks like the following:


function do_alarm(){
// determine time to wait in seconds
wait_secs=52; // for now, just define it
// wait for time to be up & sound alarm
setTimeout(sound_alarm(), (wait_secs * 1000))
}


This works great, but it is hard to tell, because nothing changes after you press the button until the time is up. However, the DOM can help us with this as well. I added the following 2 lines to the beginning of the do_alarm() function:


// mark alarm as set
document.getElementById("alarm_button").disabled=true
document.getElementById("alarm_button").value="Alarm Set"


This changes the button we pushed to set the alarm to say "Alarm Set" and disables it. If we want to be able to use the alarm again, we'll have to change the button back to it's original state. I added this to the sound_alarm() function. You can view all the code and try out a working example here.

This site needs an editor - click to learn more!

Add Hearing+Dog+Training+Tool+%96+setTimeout%28%29 to Twitter Add Hearing+Dog+Training+Tool+%96+setTimeout%28%29 to Facebook Add Hearing+Dog+Training+Tool+%96+setTimeout%28%29 to MySpace Add Hearing+Dog+Training+Tool+%96+setTimeout%28%29 to Del.icio.us Digg Hearing+Dog+Training+Tool+%96+setTimeout%28%29 Add Hearing+Dog+Training+Tool+%96+setTimeout%28%29 to Yahoo My Web Add Hearing+Dog+Training+Tool+%96+setTimeout%28%29 to Google Bookmarks Add Hearing+Dog+Training+Tool+%96+setTimeout%28%29 to Stumbleupon Add Hearing+Dog+Training+Tool+%96+setTimeout%28%29 to Reddit




Program Planning Hearing Dog Alert Training Tool
Iterative Development First Pass Hearing Dog Training Tool
JavaScript Resources
RSS
Related Articles
Editor's Picks Articles
Top Ten Articles
Previous Features
Site Map


For FREE email updates, subscribe to the JavaScript / Java Newsletter


Past Issues


print
Printer Friendly
bookmark
Bookmark
tell friend
Tell a Friend
forum
Forum
email
Email Editor


Content copyright © 2014 by Julie L Baumler. All rights reserved.
This content was written by Julie L Baumler. If you wish to use this content in any manner, you need written permission. Contact BellaOnline Administration for details.

g


g features
Hearing Dog Tool - Adding Randomness

GCJ - an Independant Java Implementation

Iterative Development First Pass Hearing Dog Training Tool

Archives | Site Map

forum
Forum
email
Contact

Past Issues
memberscenter


vote
Poetry
Daily
Weekly
Monthly
Less than Monthly



BellaOnline on Facebook
g


| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2014 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor