[Javascript] [OT ]popup window close

Nick Fitzsimons nick at nickfitz.co.uk
Thu May 13 11:36:13 CDT 2004


On 13/5/04 4:57 pm, "Paul McGuire" <pmcguire at cguk.co.uk> wrote:

> Its actually reporting on a database... so the query is expected to take a
> while. I just need a courtesy message so people dont think its crashed.
> 

Non-pop-up DHTML method:

Have the page in two parts: one with the form, one with the "Please stare
vacantly at the animated GIF" message. Use CSS to show the first part and
hide the second:

    <!-- 
        this is visible when the punter first comes to the page
    -->
    <div style="display: block;" id="formContainer">
        <form...
        .../form>
    </div>

    <!-- 
        This is initially invisible, but will become visible
        when they submit the form
    -->
    <div style="display: none;" id="messageContainer">
        <h1>Please stare vacantly...</h1>
        <img src="prettyAnimation.gif" />
    </div>

Then for the onsubmit handler:

    <form action="submit.htm" onsubmit="return submitHandler();">

And finally the JavaScript function:

function submitHandler() {
    document.getElementById("formContainer").style.display = "none";
    document.getElementById("messageContainer").style.display = "block";
    return true;
}

Note that if you want to support IE4/Win, you'll need to use
document.all["formContainer"] instead of getElementById. Check out the usual
sources of info on object detection and browser sniffing for details.

The end result is that, if the form is to be submitted, the block of HTML
containing the form is hidden by modifying its style, and in its place the
message is displayed. This has the advantage that the punter can't keep
clicking "Submit". Then "true" is returned to the onsubmit handler, which in
turn returns that value, which allows the form submission to proceed.

And the animated GIF? That just makes them think something is happening :-)

(If you need to support Netscape/IE version 3, you can produce a similar
effect through a wild and wonderful technique I developed several years ago,
but the margins of this email are too small to contain it.)

HTH,

Nick Fitzsimons.
-- 
Nick Fitzsimons
nick at nickfitz.co.uk





More information about the Javascript mailing list