473,386 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Redirecting Form.Submit() to an event handler

1
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>
Aug 6 '07 #1
1 10750
acoder
16,027 Expert Mod 8TB
Moved from the Articles section.
Aug 6 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Halldór Ísak Gylfason | last post by:
In my application I have an iframe that is empty (and not visible) initially, however when a user presses a button a form is programmatically submitted and the target is set to the IFrame. I...
4
by: bnp | last post by:
Hi All, I am quite new the JavaScript. Basically I am a C++ programmer, but now I am working on JavaScript since last 5 days. I have a problem regarding the form validation. I have created a...
2
by: Andy Goldstein | last post by:
I have a table where all the TRs have an onClick handler registered. One (and only one) of the rows has 2 text input boxes, where each textbox has an onChange handler registered. Both the onClick...
4
by: Jiho Han | last post by:
What is the best way to check whether the page is simply a postback or the form has been submit with the intention of doing something? In the olden days, I used to check for a form field name...
6
by: varkey.mathew | last post by:
Hi there, I have a basic form with a postback. The following is a line of dynamic code written so that when the user clicks on the Button control, he will receive a confirm messagebox. ...
4
by: josh.dutcher | last post by:
I'm trying to set up a simple "change your password" form. I've got an AJAX process that is checking the new password the user enters against their current password to make sure they're changing...
2
by: patrick73 | last post by:
I would like to submit a standard html form using the XMLHttpRequest object. As far as I can tell there is no easy way to do this. What I have to do is: 1 Register an event handler on the forms...
4
by: sameergn | last post by:
Hi, I have an image in my HTML form which has onclick() handler. There is also a submit button and a text box. Whenever text box has focus and user presses enter, the onclick() event of...
3
by: prodizy | last post by:
Hi, In Firefox, what's the best way of tracking the form submit? The following are two ways I tried, but they won't work if the form is submitted through JavaScript. Method 1: using the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.