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

commandButton default on Enter

I have a Visualforce page that is building a list of values.  I'd like my "Next Record" button's action to run anytime the user hits ENTER on the keyboard.  Is there a way to make that happen?



<apex:commandButton title="Next Record" value="NextRec" action="{!NextRec}" />




I had a VF page with few input field and commandbuttons. So when we enter values and hit the ENTER key, it would call the first command button action by default.


Not sure why its not working for you.




The behavior of a pressed return key in a form varies between browsers.  I think Firefox does a good job of automatically mapping the enter key for you, but generally you have to drop into javascript if you want consistent behavior and even then I think some browsers don't support the method.  (In particular I remember one nasty bug with IE that would behave differently depending on how many inputs were in your form, and the workaround was stashing an empty hidden input on your page).


There are quite a few discussions on this on the forums and definitely all over the web, so I think Google is your best bet, to be honest.  Just make sure you test it in all of your supported browsers.