+ Start a Discussion
Ken KoellnerKen Koellner 

Enter key on apex:InputText causing submit of command button

I have an apex:InputText field.  Hitting Enter in the field causes the next CommandButton on the page to be executed.  I do not what that to happen.  The commandButton is not even the next element on the page.  I have several inputText entries.  If I hit enter in the first one, the next CommandButton on the page is executed.


Anyone know if there's a way to defeat that functionality?


I see documentation on the "accessKey" attribute on commandButton but no details.  I don't have that specified and don't know if specifying anything here could cause the functionality to be defeated.


Any ideas?


There's one case in my application where hitting Enter and executing the next CommandButton on the page would make sense.  Everywhere else it does not.  I really want to turn that functionality off in those cases.


Enter this script in your page :

function ignoreEnterKey(e){
    if ((window.event&&window.event.keyCode==13) || e.which==13) {
        return false;
    } else {
        return true;


and then in your inputText field have an onKeyUp attribute like this :

    <apex:inputText id="?????" value="{!???????????}" onkeyup="ignoreEnterKey(event);"/>