# Ajax submit: Clicking 'Submit' vs. hitting ENTER

**URL:** <https://www.ruby-forum.com/t/ajax-submit-clicking-submit-vs-hitting-enter/189268>\
**Category:** Rails\
**Created:** [May 27, 2010, 7:24pm UTC](https://www.ruby-forum.com/t/ajax-submit-clicking-submit-vs-hitting-enter/189268 "2010-05-27T19:24:26Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [May 27, 2010, 7:24pm UTC](https://www.ruby-forum.com/t/ajax-submit-clicking-submit-vs-hitting-enter/189268/1 "2010-05-27T19:24:26Z")

</div>

Hi there,

Has anyone an idea why the below form

- submits correctly when I click the ‘Submit’ button
- but does call the ‘new’ action instead of ‘create’ when I hit ENTER?

\<% form\_remote\_tag :html =\> { :action =\> url\_for(:controller =\> ‘pages’,  
:action =\> ‘create’) }  
do -%\>

\<%= text\_field :page, :title %\>  
\<%= submit\_to\_remote ‘blah’, ‘Submit’, :url =\> {:controller =\>  
‘pages’,  
:action =\> ‘create’}  
%\>

\<% end -%\>

Thanks a lot for any hints!  
Tom

---

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [May 27, 2010, 10:05pm UTC](https://www.ruby-forum.com/t/ajax-submit-clicking-submit-vs-hitting-enter/189268/2 "2010-05-27T22:05:39Z")

</div>

On 27 May 2010 18:24, Tom Ha [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> \<%= text\_field :page, :title %\>  
> \<%= submit\_to\_remote ‘blah’, ‘Submit’, :url =\> {:controller =\>  
> ‘pages’,  
> :action =\> ‘create’}  
> %\>
> 
> \<% end -%\>

Firstly it may be worth checking the html of the page is valid (view  
the source in your browser and copy and paste the complete html into  
the w3c html validator - find it with google if necessary).

Assuming html is valid is it possible that Enter is hitting a  
different button or link on the page? Does the log give any clues?  
I seem to remember a discussion here about this a little time ago, but  
I don’t remember the result. A bit of searching here and googling may  
be useful.

Colin

---

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [May 27, 2010, 11:35pm UTC](https://www.ruby-forum.com/t/ajax-submit-clicking-submit-vs-hitting-enter/189268/3 "2010-05-27T23:35:14Z")

</div>

On Thu, May 27, 2010 at 1:03 PM, Colin L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Assuming html is valid is it possible that Enter is hitting a  
> different button or link on the page? Does the log give any clues?

Besides the above, use FF/Firebug to

1. confirm there are no JavaScript errors occurring
2. compare the network traffic generated by each event

## FWIW,

Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan

---

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [May 28, 2010, 2:19pm UTC](https://www.ruby-forum.com/t/ajax-submit-clicking-submit-vs-hitting-enter/189268/4 "2010-05-28T14:19:38Z")

</div>

On May 27, 10:24 pm, Tom Ha [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> \<%= text\_field :page, :title %\>  
> \<%= submit\_to\_remote ‘blah’, ‘Submit’, :url =\> {:controller =\>  
> ‘pages’,  
> :action =\> ‘create’}  
> %\>
> 
> \<% end -%\>

You should confirm that your page has multiple form\_tags? as like  
form within another(inner forms).  
actions is going to the first form action when you are using 2 forms  
in your page  
You can try with the following  
\<%=javascript\_include\_tag “prototype”%\>

 \<%= text\_field :page, :title %\> \<%= submit\_to\_remote 'blah', 'Submit', :url =\> {:action =\> 'create'},:update=\>"SS"%\>

---

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [May 27, 2010, 11:37pm UTC](https://www.ruby-forum.com/t/ajax-submit-clicking-submit-vs-hitting-enter/189268/5 "2010-05-27T23:37:34Z")

</div>

On May 27, 6:24 pm, Tom Ha [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> \<%= text\_field :page, :title %\>  
> \<%= submit\_to\_remote ‘blah’, ‘Submit’, :url =\> {:controller =\>  
> ‘pages’,  
> :action =\> ‘create’}  
> %\>
> 
> \<% end -%\>

Well it should be ok to have that submit tag just be a normal submit  
tag. Secondly if my memory is correct, passing the html =\> :action  
option is only for setting up a fallthrough for if the user doesn’t  
have javascript (check what gets generated). You also need to say  
something like form\_remote\_tag :url =\> {:controller =\> pages …

Fred

---

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [May 28, 2010, 2:20pm UTC](https://www.ruby-forum.com/t/ajax-submit-clicking-submit-vs-hitting-enter/189268/6 "2010-05-28T14:20:13Z")

</div>

On May 27, 10:24 pm, Tom Ha [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> \<%= text\_field :page, :title %\>  
> \<%= submit\_to\_remote ‘blah’, ‘Submit’, :url =\> {:controller =\>  
> ‘pages’,  
> :action =\> ‘create’}  
> %\>
> 
> \<% end -%\>

You should confirm that your page has multiple form\_tags? as like  
form within another(inner forms).  
actions is going to the first form action when you are using 2 forms  
in your page  
You can try with the following  
\<%=javascript\_include\_tag “prototype”%\>

 \<%= text\_field :page, :title %\> \<%= submit\_to\_remote 'blah', 'Submit', :url =\> {:action =\> 'create'},:update=\>"SS"%\>

---

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [May 28, 2010, 2:22pm UTC](https://www.ruby-forum.com/t/ajax-submit-clicking-submit-vs-hitting-enter/189268/7 "2010-05-28T14:22:34Z")

</div>

On May 27, 10:24 pm, Tom Ha [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> \<%= text\_field :page, :title %\>  
> \<%= submit\_to\_remote ‘blah’, ‘Submit’, :url =\> {:controller =\>  
> ‘pages’,  
> :action =\> ‘create’}  
> %\>
> 
> \<% end -%\>

You should confirm that your page has multiple form\_tags? as like  
form within another(inner forms).  
actions is going to the first form action when you are using 2 forms  
in your page  
You can try with the following  
\<%=javascript\_include\_tag “prototype”%\>

 \<%= text\_field :page, :title %\> \<%= submit\_to\_remote 'blah', 'Submit', :url =\> {:action =\> 'create'},:update=\>"SS"%\>

---

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [May 28, 2010, 4:40pm UTC](https://www.ruby-forum.com/t/ajax-submit-clicking-submit-vs-hitting-enter/189268/8 "2010-05-28T16:40:11Z")

</div>

Thanks for all the feedback!

Fred’s nailed it and all other hints were instructive as well!
