How to attach an event to the onSubmit event of a form with the binding of previously applied methods?

Actaully my application contains hundreds of pages. Now I need to attach the "disablePage" event to the onSubmit form. I do not want to go to every page and write:

<form name="frmname" onSubmit="disablePage();">

What am I doing now: -

excerpt from the common.js file; [included on all pages]

/* we have to attach 'attachFormSubmit' method on onLoad event, 
   otherwise forms[0] will always be null. If there is any alternative, 
   then please suggest one */
if (window.addEventListener){   
    window.addEventListener('load', attachFormSubmit, false); 
} else if (window.attachEvent){ 
    window.attachEvent('onload', attachFormSubmit );
}

function attachFormSubmit(){
    forms = document.getElementsByTagName('Form');  
    if ( forms[0] ){  // there is only one form in all pages    
        if (forms[0].addEventListener){         
            forms[0].addEventListener('submit', disablePage, false); 
        } else if (forms[0].attachEvent){           
            forms[0].attachEvent('onsubmit', disablePage);
        }
    }
}

function disablePage(){     
    document.getElementById("pageHideDivID").style.display='inline';        
}

Up to this point, everything is in order, disablePage () is bound to the forms of the entire page.

But the problem is that if someone has already bound a method to onSubmit or onLoad, this should also be done. And I think, according to my code, the code will never be executed. What should I do to link their method?

No JQuery please

+5
2

Quirksmode , , . , . addEventListener/attachEvent onsubmit.

+4

, , ( , ), , :

. onsubmit . , "" , , ...

+1

All Articles