<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: The form that left</title>
	<atom:link href="http://www.robertnyman.com/2008/02/29/the-form-that-left/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.robertnyman.com/2008/02/29/the-form-that-left/</link>
	<description>Web development and Internet trends</description>
	<pubDate>Tue, 06 Jan 2009 07:49:03 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
		<item>
		<title>By: Robert Nyman</title>
		<link>http://www.robertnyman.com/2008/02/29/the-form-that-left/#comment-293944</link>
		<dc:creator>Robert Nyman</dc:creator>
		<pubDate>Wed, 04 Jun 2008 18:33:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2008/02/29/the-form-that-left/#comment-293944</guid>
		<description>Diego,

Thanks for sharing!
I'll try to take a look at in the future.</description>
		<content:encoded><![CDATA[<p>Diego,</p>
<p>Thanks for sharing!<br />
I&#8217;ll try to take a look at in the future.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Diego Perini</title>
		<link>http://www.robertnyman.com/2008/02/29/the-form-that-left/#comment-292737</link>
		<dc:creator>Diego Perini</dc:creator>
		<pubDate>Tue, 03 Jun 2008 16:13:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2008/02/29/the-form-that-left/#comment-292737</guid>
		<description>Robert,
here are my tests as promised, I know you are busy now, so these can wait until you are back.

Anyway if somebody else reading can give a look and help find some inconsistency it would let me improve it, maybe other situation that it doesn't actually cover.

http://javascript.nwbox.com/formsCop/

There are two versions, the oldest one (0.5) that I tweaked a bit to log information, and the newer one (0.8) that I am in the process of updating as soon as I find more misbehaviors / bugs.

Both will now log to Firebug console and window status, so enable "writing to status bar" in your browser if you want to see some info
or open the Firebug console.

--
Diego Perini</description>
		<content:encoded><![CDATA[<p>Robert,<br />
here are my tests as promised, I know you are busy now, so these can wait until you are back.</p>
<p>Anyway if somebody else reading can give a look and help find some inconsistency it would let me improve it, maybe other situation that it doesn&#8217;t actually cover.</p>
<p><a href="http://javascript.nwbox.com/formsCop/" rel="nofollow">http://javascript.nwbox.com/formsCop/</a></p>
<p>There are two versions, the oldest one (0.5) that I tweaked a bit to log information, and the newer one (0.8) that I am in the process of updating as soon as I find more misbehaviors / bugs.</p>
<p>Both will now log to Firebug console and window status, so enable &#8220;writing to status bar&#8221; in your browser if you want to see some info<br />
or open the Firebug console.</p>
<p>&#8211;<br />
Diego Perini</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert Nyman</title>
		<link>http://www.robertnyman.com/2008/02/29/the-form-that-left/#comment-289506</link>
		<dc:creator>Robert Nyman</dc:creator>
		<pubDate>Sat, 31 May 2008 18:05:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2008/02/29/the-form-that-left/#comment-289506</guid>
		<description>Diego,

Sounds interesting.
However, this brings an extra dimension, that for one isn't that good, to event delegation, just to solve a fairly small problem in a general way.

However, there are cases where it could indeed be proved useful, so please let me know about your solution when it is put together.</description>
		<content:encoded><![CDATA[<p>Diego,</p>
<p>Sounds interesting.<br />
However, this brings an extra dimension, that for one isn&#8217;t that good, to event delegation, just to solve a fairly small problem in a general way.</p>
<p>However, there are cases where it could indeed be proved useful, so please let me know about your solution when it is put together.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Diego Perini</title>
		<link>http://www.robertnyman.com/2008/02/29/the-form-that-left/#comment-288561</link>
		<dc:creator>Diego Perini</dc:creator>
		<pubDate>Fri, 30 May 2008 17:45:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2008/02/29/the-form-that-left/#comment-288561</guid>
		<description>Robert,
I was reviewing some of my old work on forms and found something which is usable. It turns out that in IE this trick is also possible.

Just go through all the forms in the document and overwrite the "submit" methods to refer to the validator function. This must be done before "onload".

If you want to cancel the "onsubmit", capture the "onclick" event at the document level and cancel it's "default action" by setting:

   event.returnValue = false;

Trapping "mousedown" or "mouseup" will not work as with "onclick".

I will soon post my "formsCop" in my lab site, I have actually revived it.

--
Diego Perini</description>
		<content:encoded><![CDATA[<p>Robert,<br />
I was reviewing some of my old work on forms and found something which is usable. It turns out that in <acronym title="Internet Explorer">IE</acronym> this trick is also possible.</p>
<p>Just go through all the forms in the document and overwrite the &#8220;submit&#8221; methods to refer to the validator function. This must be done before &#8220;onload&#8221;.</p>
<p>If you want to cancel the &#8220;onsubmit&#8221;, capture the &#8220;onclick&#8221; event at the document level and cancel it&#8217;s &#8220;default action&#8221; by setting:</p>
<p>   event.returnValue = false;</p>
<p>Trapping &#8220;mousedown&#8221; or &#8220;mouseup&#8221; will not work as with &#8220;onclick&#8221;.</p>
<p>I will soon post my &#8220;formsCop&#8221; in my lab site, I have actually revived it.</p>
<p>&#8211;<br />
Diego Perini</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert Nyman</title>
		<link>http://www.robertnyman.com/2008/02/29/the-form-that-left/#comment-224102</link>
		<dc:creator>Robert Nyman</dc:creator>
		<pubDate>Wed, 05 Mar 2008 13:42:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2008/02/29/the-form-that-left/#comment-224102</guid>
		<description>Diego,

Absolutely, using the &lt;code&gt;HTMLFormElement&lt;/code&gt; is a great way to do it, but always leaves us with IE and how to solve it there. I don't know of an equivalent workaround either.</description>
		<content:encoded><![CDATA[<p>Diego,</p>
<p>Absolutely, using the <code>HTMLFormElement</code> is a great way to do it, but always leaves us with <acronym title="Internet Explorer">IE</acronym> and how to solve it there. I don&#8217;t know of an equivalent workaround either.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Diego Perini</title>
		<link>http://www.robertnyman.com/2008/02/29/the-form-that-left/#comment-223693</link>
		<dc:creator>Diego Perini</dc:creator>
		<pubDate>Wed, 05 Mar 2008 00:54:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2008/02/29/the-form-that-left/#comment-223693</guid>
		<description>Simon,
your method is the working one, I was battling with that too in my event delegation code. The requested functionality here is being able to catch the "form.submit()" that may have been invoked by javascript programmatically, so overwriting that method may be the best cross-browser solution.

Robert,
for W3C browsers that exposes this method it will be possible to prototype the HTMLFormElement, this could be a solution when having multiple forms to fix on the same page; no way to do that in IE that I know.</description>
		<content:encoded><![CDATA[<p>Simon,<br />
your method is the working one, I was battling with that too in my event delegation code. The requested functionality here is being able to catch the &#8220;form.submit()&#8221; that may have been invoked by javascript programmatically, so overwriting that method may be the best cross-browser solution.</p>
<p>Robert,<br />
for <acronym title="World Wide Web Consortium">W3C</acronym> browsers that exposes this method it will be possible to prototype the HTMLFormElement, this could be a solution when having multiple forms to fix on the same page; no way to do that in <acronym title="Internet Explorer">IE</acronym> that I know.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert Nyman</title>
		<link>http://www.robertnyman.com/2008/02/29/the-form-that-left/#comment-222511</link>
		<dc:creator>Robert Nyman</dc:creator>
		<pubDate>Mon, 03 Mar 2008 08:13:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2008/02/29/the-form-that-left/#comment-222511</guid>
		<description>Simon, Tanny,

Your approach is definitely better. Override the &lt;code&gt;submit&lt;/code&gt; to do what you want,k such as validation, and then perform a call, through a saved reference, to the native method.

Milo,

Very true and very interesting. I mean, I agree, that's life, but since this is apparently intentional behavior, I would really like to learn the mindset behind it.

Phil,

Hope it helps!

Andy,

Well, that is clever, but it takes for granted that a &lt;code&gt;onsubmit&lt;/code&gt; event has been applied; therefore, a check should be first if any event handler exists. And, what happens if you have multiple event handlers? (just talking and thinking, without actually testing now :-) )</description>
		<content:encoded><![CDATA[<p>Simon, Tanny,</p>
<p>Your approach is definitely better. Override the <code>submit</code> to do what you want,k such as validation, and then perform a call, through a saved reference, to the native method.</p>
<p>Milo,</p>
<p>Very true and very interesting. I mean, I agree, that&#8217;s life, but since this is apparently intentional behavior, I would really like to learn the mindset behind it.</p>
<p>Phil,</p>
<p>Hope it helps!</p>
<p>Andy,</p>
<p>Well, that is clever, but it takes for granted that a <code>onsubmit</code> event has been applied; therefore, a check should be first if any event handler exists. And, what happens if you have multiple event handlers? (just talking and thinking, without actually testing now <img src='http://www.robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> )</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy</title>
		<link>http://www.robertnyman.com/2008/02/29/the-form-that-left/#comment-221947</link>
		<dc:creator>Andy</dc:creator>
		<pubDate>Sun, 02 Mar 2008 10:33:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2008/02/29/the-form-that-left/#comment-221947</guid>
		<description>Lo and behold, the one-liner:
&lt;code&gt;if (form.onsubmit()) form.submit();&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Lo and behold, the one-liner:<br />
<code>if (form.onsubmit()) form.submit();</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Phil Nash</title>
		<link>http://www.robertnyman.com/2008/02/29/the-form-that-left/#comment-221155</link>
		<dc:creator>Phil Nash</dc:creator>
		<pubDate>Sat, 01 Mar 2008 11:34:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2008/02/29/the-form-that-left/#comment-221155</guid>
		<description>I came across this exact problem yesterday myself. Not to the extent of the .NET issue, but I was surprised to see that calling form.submit() didn't trigger onsubmit.

Even weirder was the fact that I was using an object that I'd called validator and its method validate()  as in Simon Proctor's comment. If I'd just read this post a day earlier I'd have had no problem!

I do like the idea of hijacking the form.submit() function to include the validation. It seems less obtrusive than just ensuring you validate before you submit, which was the solution I finished with yesterday.</description>
		<content:encoded><![CDATA[<p>I came across this exact problem yesterday myself. Not to the extent of the .NET issue, but I was surprised to see that calling form.submit() didn&#8217;t trigger onsubmit.</p>
<p>Even weirder was the fact that I was using an object that I&#8217;d called validator and its method validate()  as in Simon Proctor&#8217;s comment. If I&#8217;d just read this post a day earlier I&#8217;d have had no problem!</p>
<p>I do like the idea of hijacking the form.submit() function to include the validation. It seems less obtrusive than just ensuring you validate before you submit, which was the solution I finished with yesterday.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Milo</title>
		<link>http://www.robertnyman.com/2008/02/29/the-form-that-left/#comment-220670</link>
		<dc:creator>Milo</dc:creator>
		<pubDate>Fri, 29 Feb 2008 22:14:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2008/02/29/the-form-that-left/#comment-220670</guid>
		<description>Calling click() on a button also doesn't fire the button's OnClick handler. Changing selectedIndex on a select also doesn't fire the select's OnChange handler.

Event handlers simply don't fire unless the User performs the action.  C'est la vie.</description>
		<content:encoded><![CDATA[<p>Calling click() on a button also doesn&#8217;t fire the button&#8217;s OnClick handler. Changing selectedIndex on a select also doesn&#8217;t fire the select&#8217;s OnChange handler.</p>
<p>Event handlers simply don&#8217;t fire unless the User performs the action.  C&#8217;est la vie.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tanny O'Haley</title>
		<link>http://www.robertnyman.com/2008/02/29/the-form-that-left/#comment-220560</link>
		<dc:creator>Tanny O'Haley</dc:creator>
		<pubDate>Fri, 29 Feb 2008 19:22:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2008/02/29/the-form-that-left/#comment-220560</guid>
		<description>I have a variant of Simon's.
// Make sure that onsubmit is called even if f.submit() is called.
f._submit = f.submit;
f.submit = function() {
	if (f.onsubmit) {
		var retVal = f.onsubmit();
		if (typeof retVal == "boolean" &#38;&#38; retVal == false) {
			return false;
		}
	}
	this._submit();
};
Overwrite the submit() function with a function that checks to see if there is an onsubmit function. If there is, run onsubmit() then f._submit() if false isn't returned.

The problem is that I don't think with __doPostBack you may want to call your form validation. The __doPostBack function may be called to retrieve some information, fill in a list, ... Is there a way to know if __doPostBack is doing the final submit, which is where you would want to do your validation?</description>
		<content:encoded><![CDATA[<p>I have a variant of Simon&#8217;s.<br />
// Make sure that onsubmit is called even if f.submit() is called.<br />
f._submit = f.submit;<br />
f.submit = function() {<br />
	if (f.onsubmit) {<br />
		var retVal = f.onsubmit();<br />
		if (typeof retVal == &#8220;boolean&#8221; &amp;&amp; retVal == false) {<br />
			return false;<br />
		}<br />
	}<br />
	this._submit();<br />
};<br />
Overwrite the submit() function with a function that checks to see if there is an onsubmit function. If there is, run onsubmit() then f._submit() if false isn&#8217;t returned.</p>
<p>The problem is that I don&#8217;t think with __doPostBack you may want to call your form validation. The __doPostBack function may be called to retrieve some information, fill in a list, &#8230; Is there a way to know if __doPostBack is doing the final submit, which is where you would want to do your validation?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Simon Proctor</title>
		<link>http://www.robertnyman.com/2008/02/29/the-form-that-left/#comment-220498</link>
		<dc:creator>Simon Proctor</dc:creator>
		<pubDate>Fri, 29 Feb 2008 16:42:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2008/02/29/the-form-that-left/#comment-220498</guid>
		<description>I had a similar situation which I dealt with by for any form (f) I wanted to validate adding this.  
&lt;code&gt;f._submit = f.submit;
f.submit = function() { if (  validator.validate( this ) ) { this._submit() } };&lt;/code&gt;
Then if the &lt;code&gt;form.submit&lt;/code&gt; method is required (and some of the older parts of the app I work on do use it) the validation would still kick in.</description>
		<content:encoded><![CDATA[<p>I had a similar situation which I dealt with by for any form (f) I wanted to validate adding this.<br />
<code>f._submit = f.submit;<br />
f.submit = function() { if (  validator.validate( this ) ) { this._submit() } };</code><br />
Then if the <code>form.submit</code> method is required (and some of the older parts of the app I work on do use it) the validation would still kick in.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
