Hi All,
I have added an event handler to redirect form.submit() to a newSubmit() method that I have defined (which does some additional processing before submitting the form).
Additionally I have defined the relavant function method in the code for details)
The issue is that when Icall targetForm._submit() method from the newSubmit() function the page I get an 'Object doesn't support this property or method' error
I am using IE 6.0.2900.2189 sp2 runniong on Windows 2003 workstation
The souce code is listed below. To run thie code:
1 .Open you IE browser using the supplied html code below code
2. Click the "Register Submit Event" buttion - to register the newSubmit(0 event handler
3. Click the Submit Form button to attempt to submit the form
<html><head><title>Submit Form Fields</title></head>
<body><h2>Submitting the form elements</h2>
<form name="testForm" action="submitResult.html" method="POST">
<input type="text" name="text_entry" value="" >
<br><br>
<input type="button" name="btn_register_submit" value="Register Submit Event" onClick="registerSubmit()">
<input type="button" name="btn_submit_form" value="Submit Form" onClick="submitForm()">
</form>
<script language ="Javascript">
function newsubmit(targetForm) {
alert('New submit function invoked');
// This doe not work - get an 'Object doesn't support this property or method' error
targetForm._submit();
}
// This function registers the new submit event with the form.submit() action so that
// form.submit() isredirected to the newSubmit() instead
function registerSubmit() {
alert('Register Submit');
// Register the submit event (using the traditional event registration model)
// See: http://www.quirksmode.org/js/events_tradmod.html
testForm.submit = function() {newsubmit(testForm)};
// Note the W3C approach to registering event handlers is noted below but
// 1. I cannot get this to work in IE
// 2. I am not sure how to pass arguments to the newSubmit in this case
// See: http://www.quirksmode.org/js/events_advanced.html
//testForm.addEventListener('submit', newSubmit, false); // Mozilla / Opera
//testForm.addEventListener('submit', newSubmit); // IE syntax
// To get the submit to work correctly a function prototype for the submit() needs to be defined
// The W3C recommended syntax for this is noted below:
// See also: http://diveintogreasemonkey.org/patterns/override-method.html
/*
// capture the onsubmit event on all forms
window.addEventListener('submit', newsubmit, true);
// If a script calls someForm.submit(), the onsubmit event does not fire,
// so we need to redefine the submit method of the HTMLFormElement class.
HTMLFormElement.prototype._submit = HTMLFormElement.prototype.submit;
HTMLFormElement.prototype.submit = newsubmit;
*/
// Issue : this does not work when running in IE. The recommended synatx in IE is as noted below:
// See: // http://delete.me.uk/2004/09/ieproto.html
// Emulate the prototyping behaviour in IE 6.0.2900.2189 sp2
Element = function () {};
Element.prototype._submit = function () {Element.prototype.submit};
Element.prototype.submit = newsubmit;
// Debug - uncomment to view the function prototype contents
//alert('Element.prototype._submit =' + Element.prototype._submit);
//alert('Element.prototype.submit =' + Element.prototype.submit);
}
function submitForm() {
alert('Submit form called');
testForm.submit();
}
</script>
</body>
</html>