I take it you’re submitting the form with a different target window; hence the form staying in place.
There are several options.
- Keep the submit button disabled and do ongoing validation in the background, polling the form for changes to fields and then firing off the validation request for a field as it changes. When the form is in a valid state, enable the button; when it isn’t, disable the button. This isn’t perfect, as there will tend to be a delay, but it may be good enough for whatever you’re doing.
- Do basic validation that doesn’t require round-trips to the server in a handler for the form’s
submit
event, then submit the form and remove it (or possibly just hide it). If the further validation on the server detects a problem, it can return a page that uses JavaScript to tell the original window to re-display the form. - Use a session cookie and a unique form ID (the current time from
new Date().getTime()
would do); when the form is submitted, disable its submit button but keep it visible until the response comes back. Make the response set a session cookie with that ID indicating success/failure. Have the window containing the form poll for the cookie every second or so and act on the result when it sees it. (I’ve never done this last one; not immediately seeing why it wouldn’t work.)
I expect there are about a dozen other ways to skin this cat, but those are three that came to mind.
(Edit) If you’re not submitting to a different target, you might want to go ahead and do that — to a hidden iframe
on the same page. That (possibly combined with the above or other answers) might help you get the user experience you’re looking for.