473,551 Members | 2,803 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Redirecting Form.Submit() to an event handler

1 New Member
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._sub mit() 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><ti tle>Submit Form Fields</title></head>
<body><h2>Submi tting the form elements</h2>

<form name="testForm" action="submitR esult.html" method="POST">
<input type="text" name="text_entr y" value="" >
<input type="button" name="btn_regis ter_submit" value="Register Submit Event" onClick="regist erSubmit()">
<input type="button" name="btn_submi t_form" value="Submit Form" onClick="submit Form()">

<script language ="Javascript ">
function newsubmit(targe tForm) {
alert('New submit function invoked');

// This doe not work - get an 'Object doesn't support this property or method' error
targetForm._sub mit();


// 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(test Form)};

// 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.addEve ntListener('sub mit', newSubmit, false); // Mozilla / Opera
//testForm.addEve ntListener('sub mit', 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://diveintogreasem onkey.org/patterns/override-method.html

// capture the onsubmit event on all forms
window.addEvent Listener('submi t', 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._sub mit = HTMLFormElement .prototype.subm it;
HTMLFormElement .prototype.subm it = 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.prototy pe._submit = function () {Element.protot ype.submit};
Element.prototy pe.submit = newsubmit;

// Debug - uncomment to view the function prototype contents
//alert('Element. prototype._subm it =' + Element.prototy pe._submit);
//alert('Element. prototype.submi t =' + Element.prototy pe.submit);


function submitForm() {
alert('Submit form called');
testForm.submit ();

Aug 6 '07 #1
1 10779
16,027 Recognized Expert Moderator MVP
Moved from the Articles section.
Aug 6 '07 #2

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

Similar topics

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 want to detect when the frame has been loaded with the result of the form submit. Of course I have tried some event handlers like onload, onactivate,...
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 script that validates the form fields. the validation procedure is called ONCLICK event of the submit button. Follwowing is the structure of the...
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 and onChange handlers do some minor manipulation of form data (although they work on different form elements). If the onChange event fires, I need...
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 used for the submit button: <input type="submit" name="saverecord" value="push me to save"> Then I'd retrieve it using something like:
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. btnSubmit.Attributes.Add("onclick","return confirm('Are you sure you want to leave without saving your change(s)?');");
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 it. This function is firing via the password field's onBlur event handler. I want to do some other form validation using the form's onSubmit...
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 submit event 2 In this handler I have to: 2.1 Prevent the default action so that the form does not submit in the current window 2.2...
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 image is fired with event.keyCode as undefined. I was expecting that the form would get submitted. I tried returning from onclick() handler if keyCode...
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 window.onsubmit event handler Code: window.onsubmit=handleEvent;
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.