[Javascript] A Temporary Alert?

Mike Dougherty mdougherty at pbp.com
Sun Dec 23 21:41:35 CST 2007


On Dec 23, 2007 9:52 PM, tedd <tedd at sperling.com> wrote:

> You see, I have a database access that can take up to five seconds
> after the user clicks "Submit" and during that time I would like to
> tell the user to wait (instead of clicking things widely and throwing
> a tantrum) -- which is what I do when I don't know what's happening.
>
> I'm actually surprised that such a critter isn't a staple for
> programming GUI stuff.


HTML: <div id="WorkingNotice">Working...</div>
CSS:
#WorkingNotice {display: none;}  /* normal presentation rule */
#WorkingNotice.shown {display: block;} /* special case presentation rule */
Javascript:
/* try to get a reference to the object */
var wn = document.getElementById("WorkingNotice");
/* if the reference is valid, add the "shown" class to change its
presentation via CSS */
if( wn ) { wn.className = wn.className.replace(/\sshown/,"") + " shown"; }
    // some long-running process here
/* if the reference is valid, remove the "shown" class so its presentation
is reset to normal */
if( wn ) { wn.className = wn.className.replace(/\sshown/,"") ; }

Of course you can add a background image to this div and size and position
it however you'd like.  As Peter suggested, the idea is that you have a DOM
element in front of everything else on the screen which you can control.
(you might need to remove the "shown" className in a different method if
you're using some event-based trigger such as another element's onload)  You
might also make(or find) a more elegant function to manage the className
property of your elements.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20071223/4aaf73c1/attachment.htm>


More information about the Javascript mailing list