Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Capture form submit

Status
Not open for further replies.

elliottmina

Programmer
Feb 6, 2005
12
US
I have a page that includes a form I cannot alter. I want to capture it's submission, and do some validation. My code works fine in Firefox, but nothing happens (not even an error) in IE.
Code:
if (window.addEventListener) window.addEventListener('submit', myFunction, true);
else if (window.attachEvent) window.attachEvent('submit',myFunction);

function myFunction(){
  alert('foo');
}
Suggestions? TIA
 
>[tt]window.attachEvent('submit',myFunction);[/tt]
Replace it by attach to the definite form element. And the event in the ie event model is referred to as "onsubmit".
[tt]window.[red]document.forms[0].[/red]attachEvent('[red]on[/red]submit',myFunction);[/tt]
 
Also, as a consequence, add the whole thing within a window.onload because you need to refer to specific elements.
[tt]
window.onload=function() {
if (window.addEventListener) {
window.addEventListener('submit', myFunction, true);
} else if (window.attachEvent) {
window.document.forms[0].attachEvent('onsubmit',myFunction);
}
}
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top