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
Cindy NormanCindy Norman 

Totally disable ENTER button

I don't ever want my ENTER button to do anything.
Does anyone know how to disable it without having to put an onkeypress type event on each input field?
I have about 200 input fields of various types (inputField, inputText, radio buttons, ...)
and some commandButtons that i want them to specifically Push to fire.
Andy BoettcherAndy Boettcher

So, two answers.  =)

Official - you're looking at the onkeypress per field:  http://developer.force.com/cookbook/recipe/submit-a-form-with-the-enter-key

Unofficial - you could use some jQuery on/live handlers to bind to the onkeypress by class (just add a classname to all input fields) and cancel the enter key that way?

Cindy NormanCindy Norman
Thank you, Andy....yes, the first way has been answered many times but i have so many fields, that would get ugly. I really like the idea of the 2nd way...but i have no idea what that would look like (i'm new to this web stuff but very versed in previous incarnations of programming)...perhaps you could give me a kick start and show me some basics? Thanks either way!!
 
Cindy NormanCindy Norman
You'd think i would be able to do something on my apex:form like onkeydown="suppressEnterKey" of some sort that would take care of all of the fields inside of the form?? I have been playing with this but can't get it to respond. Is this what you were talking about, Andy?

 
Andy BoettcherAndy Boettcher
Cindy,

There is an "onkeypress" attribute for apex:form, but I haven't played with that so I'm not sure if it'll work.  (https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_form.htm)

For the jQuery route, you'd be looking at something like this:
 
<apex:includeScript value="reference to jQuery lib" />

<script>
     j$ = jQuery.noConflict();
     j$(document).ready(function () {
          j$('input,select').keypress(function(event) { return event.keyCode != 13; });
     });

</script>

Give that a whirl - see if that works.