<apex:form styleClass="container">  
<apex:actionRegion >  
  <div class="col-md-3 col-sm-5 col-xs-5 input-group">
    <apex:inputText value="{!searchString}" styleClass="form-control" html-placeholder="Search" />
    <span class="input-group-btn">
      <apex:commandButton  value="Go" action="{!Search}" rerender="searchResults" styleClass="btn btn-default"></apex:commandButton>
  <apex:pageBlock id="searchResults"> 
    <apex:pageBlockTable value="{!results}" var="a" id="tblResults" styleClass="table-gray col-md-6 col-sm-12 col-xs-12">
      <apex:column >
        <apex:facet name="header">
          <apex:outputPanel >Name</apex:outputPanel>
        <apex:outputLink value="#" onClick="Javascript:parent.setValue('{!a.Name}','{!inputId}')">{!a.Name}</apex:outputLink>     

The problem is that when I type something into the inputText and press 'enter' it does not rerender or preform the action. How can I make it so that the user can press either 'Go' or press 'enter'?


Catch the enter-key at your inputText with the onkeypress-handler and trigger a fake-click on the button:

    function handlerKeyPress(ev) {
        if (window.event && window.event.keyCode == 13 || ev.which == 13) {
            return false;
        } else {
            return true;
<apex:inputText value="{!searchString}" onkeypress="return handlerKeyPress(event);" /> 
<apex:commandButton styleClass="myUniqueSubmitButtonClass btn btn-default" value="Go" action="{!Search}" rerender="searchResults" />


  • For the sake of simplicity I use here jquery. For sure you may rewrite it also without.
  • I added "myUniqueSubmitButtonClass" to be able to select to button easily
  • While this works when I run it in the console it does not work on page. The problem is that since it is inside of a form when I press enter it submits the form and reloads the page. The way around it is press 'Go' since go does not submit the form. Is there a way to modify your code so that it will not submit the form but still allow enter to be pressed?
    – Grady D
    Sep 19 '14 at 20:38
  • 1
    I changed the code a bit. Hope it works. Have a look at this, too: developer.force.com/cookbook/recipe/…
    – Uwe Heim
    Sep 19 '14 at 20:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.