function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jeremy_rossjeremy_ross 

Need action method called if user presses Enter to submit form

In a form with only one button, if a user hits enter to submit, the submit button's action does not get called.  Other than javascript, is there a way to call a controller method when the user submits the form by pressing Enter?

Note that in my case, the form button is using reRender.  Not sure if that has any effect on the above.

Jeremy
Sam.arjSam.arj
 See this post take care of your problem:

http://salesforcesource.blogspot.com/2008/09/search-box-that-searches-when-user-hits.html

http://salesforcesource.blogspot.com/2008/09/search-box-that-searches-when-user-hits.html

Cheers
jeremy_rossjeremy_ross
Sam,

Thanks for the link.

Would you happen to know if salesforce has a fix planned for this so the javascript hack is not required?

Jeremy
jwetzlerjwetzler
you shouldn't need a javascript hack.

If you have a single button in a form, that button should get fired when you press enter.  There is, however, a bug in IE (not Visualforce) where the button is not fired on enter if there's only one input in the form.  The workaround (in Visualforce and in HTML) is to add an empty input that's hidden by CSS to the form.

This workaround has been successful for us without the need for javascript, so I'm not sure why you had to resort to it.