[thelist] Disable Multiple Forms with JavaScript

Matt Warden mwarden at gmail.com
Tue Aug 3 14:01:15 CDT 2004


On Tue, 3 Aug 2004 12:25:04 -0500, Mike Carlson <mike at mcarlson.net> wrote:
> Peter:
> 
> Thanks for the code. I am running into a problem though. It works perfectly in FireFox .9 but not in IE 6. I get some JS error about Object Expected in IE.
> 
> Any ideas? I fixed the wrap but otherwise the code is exactly 
>the same. Like I said it works in Mozilla just fine. I have no 
>image input type, just text boxes and buttons.

Take care to only execute this code after the forms have loaded.
Otherwise, they won't have been added to the DOM yet.

To do this, either put the code at the bottom of the page (e.g. after
</body>) or, as I prefer, just add it to the window.onload even
handler. To do the latter, you'll have to make the above code a
function and set it to window.onload, like so:

function disableForms() {

var currentForm;

for(var iForm=0;iForm<document.forms.length;iForm++) {
       currentForm = document.forms[iForm];
       /* I assume this is how you disable a form,
       if such a thing can be done. */
       currentForm.disabled = true;
       // The next line will probably wrap
       for(var
iElement=0;iElement<currentForm.elements.length;iElement++) {
               currentForm.elements[iElement].disabled = true;
               }
       }

}

window.onload = disableForms();


Note that I am overwriting window.onload, so if you currently have
anything in window.onload, doing the above will break that. There are
ways of adding another function to window.onload (but they don't work
in all browsers). If you need this, just ask (or google).


Thanks,

-- 

Matt Warden
Berry Neuroscience Lab
Department of Psychology
Miami University



This email proudly and graciously contributes to entropy.


More information about the thelist mailing list