[Javascript] code: disable & re-enable button

Shawn Milo ShawnMilo at runbox.com
Thu Aug 12 14:23:51 CDT 2004


Here it is:

In the <form> tag of the main page:
onsubmit="this.btnSubmit.disabled = true;"

Doing it in the form tag was necessary because doing it in the onclick
of the button cancels the form submission, and I didn't want to have to
use another function in my .js include file.

In the target window of the submitted form:

<body onload="window.focus();  
window.opener.document.forms['frmStats'].btnSubmit.disabled = false; ">



This does the trick.  If the window has not been opened yet, it pops up in
front.  If it's hiding in the background, the button is disabled until it loads,
which obscures the main window anyway.  Next time they go back to the
main page, the button is enabled again.

Now, the only problem here is if the second page blows up, due to some
error with the database or something.  I'll have to put something in there
to reset the button after 10 seconds or so.

Shawn




More information about the Javascript mailing list