<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Default html button submit on enter with JQuery</title>
	<atom:link href="http://greatwebguy.com/programming/dom/default-html-button-submit-on-enter-with-jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://greatwebguy.com/programming/dom/default-html-button-submit-on-enter-with-jquery/</link>
	<description>Self-proclaimed greatness is a hard thing to prove.</description>
	<lastBuildDate>Mon, 01 Mar 2010 19:05:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Philip Hofstetter</title>
		<link>http://greatwebguy.com/programming/dom/default-html-button-submit-on-enter-with-jquery/comment-page-1/#comment-1229</link>
		<dc:creator>Philip Hofstetter</dc:creator>
		<pubDate>Mon, 15 Feb 2010 08:50:40 +0000</pubDate>
		<guid isPermaLink="false">http://greatwebguy.com/?p=47#comment-1229</guid>
		<description>in my case I decided to take the &quot;put an invisible clone of the submit button as the first element of the form&quot;-approach.

That felt saver than to hack a script to try and detect the enter key (the key codes are not really formalized. A browser could send a different code for enter). 

Here&#039;s what I used (specific to my page layout where the last button is the default button):

        $(&#039;form&#039;).each(function(){
            var $f = $(this);
            $f.prepend($f.find(&#039;button:last&#039;)
                .clone()
                .css({
                    position: &#039;absolute&#039;,
                    left: &quot;-999px&quot;,
                    top: &quot;-999px&quot;,
                    height: 0,
                    width: 0
                })
            );
        });

I would have preferred visibility: hidden or even display:none, but IE doesn&#039;t play with that idea and only submits buttons it thinks are visible (even though that clone certainly isn&#039;t).</description>
		<content:encoded><![CDATA[<p>in my case I decided to take the &#8220;put an invisible clone of the submit button as the first element of the form&#8221;-approach.</p>
<p>That felt saver than to hack a script to try and detect the enter key (the key codes are not really formalized. A browser could send a different code for enter). </p>
<p>Here&#8217;s what I used (specific to my page layout where the last button is the default button):</p>
<p>        $(&#8216;form&#8217;).each(function(){<br />
            var $f = $(this);<br />
            $f.prepend($f.find(&#8216;button:last&#8217;)<br />
                .clone()<br />
                .css({<br />
                    position: &#8216;absolute&#8217;,<br />
                    left: &#8220;-999px&#8221;,<br />
                    top: &#8220;-999px&#8221;,<br />
                    height: 0,<br />
                    width: 0<br />
                })<br />
            );<br />
        });</p>
<p>I would have preferred visibility: hidden or even display:none, but IE doesn&#8217;t play with that idea and only submits buttons it thinks are visible (even though that clone certainly isn&#8217;t).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lars Peter Thomsen</title>
		<link>http://greatwebguy.com/programming/dom/default-html-button-submit-on-enter-with-jquery/comment-page-1/#comment-1221</link>
		<dc:creator>Lars Peter Thomsen</dc:creator>
		<pubDate>Tue, 09 Feb 2010 14:13:15 +0000</pubDate>
		<guid isPermaLink="false">http://greatwebguy.com/?p=47#comment-1221</guid>
		<description>there may be a small problem with  fields: When a dropdown is open, the user can navigate the options with the keyboard, and under normal circumstances press enter to select the marked option. With this script, however, the form is instantly submitted when he tries this, which is not desirable.</description>
		<content:encoded><![CDATA[<p>there may be a small problem with  fields: When a dropdown is open, the user can navigate the options with the keyboard, and under normal circumstances press enter to select the marked option. With this script, however, the form is instantly submitted when he tries this, which is not desirable.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Indialike</title>
		<link>http://greatwebguy.com/programming/dom/default-html-button-submit-on-enter-with-jquery/comment-page-1/#comment-1204</link>
		<dc:creator>Indialike</dc:creator>
		<pubDate>Wed, 27 Jan 2010 04:50:44 +0000</pubDate>
		<guid isPermaLink="false">http://greatwebguy.com/?p=47#comment-1204</guid>
		<description>Very nice and useful tutorials for web designers,
Thanks for posting.</description>
		<content:encoded><![CDATA[<p>Very nice and useful tutorials for web designers,<br />
Thanks for posting.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan</title>
		<link>http://greatwebguy.com/programming/dom/default-html-button-submit-on-enter-with-jquery/comment-page-1/#comment-1176</link>
		<dc:creator>Dan</dc:creator>
		<pubDate>Fri, 04 Dec 2009 20:33:40 +0000</pubDate>
		<guid isPermaLink="false">http://greatwebguy.com/?p=47#comment-1176</guid>
		<description>Thanks!</description>
		<content:encoded><![CDATA[<p>Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: YOUR-TITLE</title>
		<link>http://greatwebguy.com/programming/dom/default-html-button-submit-on-enter-with-jquery/comment-page-1/#comment-1166</link>
		<dc:creator>YOUR-TITLE</dc:creator>
		<pubDate>Sat, 21 Nov 2009 02:05:24 +0000</pubDate>
		<guid isPermaLink="false">http://greatwebguy.com/?p=47#comment-1166</guid>
		<description>&lt;strong&gt;Default html button submit on enter with JQuery - GreatWebGuy...&lt;/strong&gt;

Thank you for submitting this cool story - Trackback from YOUR-TITLE...</description>
		<content:encoded><![CDATA[<p><strong>Default html button submit on enter with JQuery &#8211; GreatWebGuy&#8230;</strong></p>
<p>Thank you for submitting this cool story &#8211; Trackback from YOUR-TITLE&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stinky69</title>
		<link>http://greatwebguy.com/programming/dom/default-html-button-submit-on-enter-with-jquery/comment-page-1/#comment-1135</link>
		<dc:creator>Stinky69</dc:creator>
		<pubDate>Tue, 13 Oct 2009 07:27:55 +0000</pubDate>
		<guid isPermaLink="false">http://greatwebguy.com/?p=47#comment-1135</guid>
		<description>This is realy good and worth to read. ,</description>
		<content:encoded><![CDATA[<p>This is realy good and worth to read. ,</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Love's Official ASP.NET Blog : Setting the Default Input Focus and Default Button : Thin ASP.NET 5</title>
		<link>http://greatwebguy.com/programming/dom/default-html-button-submit-on-enter-with-jquery/comment-page-1/#comment-1054</link>
		<dc:creator>Chris Love's Official ASP.NET Blog : Setting the Default Input Focus and Default Button : Thin ASP.NET 5</dc:creator>
		<pubDate>Sun, 24 May 2009 20:46:56 +0000</pubDate>
		<guid isPermaLink="false">http://greatwebguy.com/?p=47#comment-1054</guid>
		<description>[...] key to the desired behavior when the user presses the ENTER key. I found a good article explaining how to set a form’s default button behavior with JQuery. I did change the code from the article by making it only return true. I did this because returning [...]</description>
		<content:encoded><![CDATA[<p>[...] key to the desired behavior when the user presses the ENTER key. I found a good article explaining how to set a form’s default button behavior with JQuery. I did change the code from the article by making it only return true. I did this because returning [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michiel</title>
		<link>http://greatwebguy.com/programming/dom/default-html-button-submit-on-enter-with-jquery/comment-page-1/#comment-954</link>
		<dc:creator>Michiel</dc:creator>
		<pubDate>Mon, 02 Mar 2009 11:32:51 +0000</pubDate>
		<guid isPermaLink="false">http://greatwebguy.com/?p=47#comment-954</guid>
		<description>I&#039;m currently using jQuery 1.3.1. And to make it even more compatible with most of the common situations and less error prone, I&#039;m using the following code:

&lt;blockquote&gt;
jQuery(document).ready(function() {
	$(&quot;form input, form select&quot;).live(&#039;keypress&#039;, function (e) {
		if ($(this).parents(&#039;form&#039;).find(&#039;button[type=submit].default, input[type=submit].default&#039;).length &lt;= 0)
			return true;
		
		if ((e.which &amp;&amp; e.which == 13) &#124;&#124; (e.keyCode &amp;&amp; e.keyCode == 13)) {
			$(this).parents(&#039;form&#039;).find(&#039;button[type=submit].default, input[type=submit].default&#039;).click();
			return false;
		} else {
			return true;
		}
	});
});
&lt;/blockquote&gt;

This uses live so it also will work on newly added elements. And will also work on select elements. And also works on multiple forms. So it searches for the parent form of the element and uses that to find the submit button. As well as button form as input form.</description>
		<content:encoded><![CDATA[<p>I&#8217;m currently using jQuery 1.3.1. And to make it even more compatible with most of the common situations and less error prone, I&#8217;m using the following code:</p>
<blockquote><p>
jQuery(document).ready(function() {<br />
	$(&#8220;form input, form select&#8221;).live(&#8216;keypress&#8217;, function (e) {<br />
		if ($(this).parents(&#8216;form&#8217;).find(&#8216;button[type=submit].default, input[type=submit].default&#8217;).length &lt;= 0)<br />
			return true;</p>
<p>		if ((e.which &amp;&amp; e.which == 13) || (e.keyCode &amp;&amp; e.keyCode == 13)) {<br />
			$(this).parents(&#8216;form&#8217;).find(&#8216;button[type=submit].default, input[type=submit].default&#8217;).click();<br />
			return false;<br />
		} else {<br />
			return true;<br />
		}<br />
	});<br />
});
</p></blockquote>
<p>This uses live so it also will work on newly added elements. And will also work on select elements. And also works on multiple forms. So it searches for the parent form of the element and uses that to find the submit button. As well as button form as input form.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bruce</title>
		<link>http://greatwebguy.com/programming/dom/default-html-button-submit-on-enter-with-jquery/comment-page-1/#comment-905</link>
		<dc:creator>Bruce</dc:creator>
		<pubDate>Wed, 17 Dec 2008 17:46:17 +0000</pubDate>
		<guid isPermaLink="false">http://greatwebguy.com/?p=47#comment-905</guid>
		<description>In using JSF we found that without the return false and return true lines in this example that Firefox worked and IE didn&#039;t behave as we expected.  In IE the form was submitted, but we didn&#039;t get the expected action execution on the back end nor the expected JSF error message on the screen.  Best I can tell, the return false intercepts the default IE behavior which is to submit the form via the form definition (if that makes sense) as opposed to &quot;pushing the button&quot; which JSF knows which action to call.</description>
		<content:encoded><![CDATA[<p>In using JSF we found that without the return false and return true lines in this example that Firefox worked and IE didn&#8217;t behave as we expected.  In IE the form was submitted, but we didn&#8217;t get the expected action execution on the back end nor the expected JSF error message on the screen.  Best I can tell, the return false intercepts the default IE behavior which is to submit the form via the form definition (if that makes sense) as opposed to &#8220;pushing the button&#8221; which JSF knows which action to call.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rajeev</title>
		<link>http://greatwebguy.com/programming/dom/default-html-button-submit-on-enter-with-jquery/comment-page-1/#comment-753</link>
		<dc:creator>rajeev</dc:creator>
		<pubDate>Thu, 20 Nov 2008 07:23:15 +0000</pubDate>
		<guid isPermaLink="false">http://greatwebguy.com/?p=47#comment-753</guid>
		<description>testing</description>
		<content:encoded><![CDATA[<p>testing</p>
]]></content:encoded>
	</item>
</channel>
</rss>
