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
TejTej 

Search by Enter key in Visual force page

I want to invoke the search functionality by pressing the search button or by clicking the enter key.

 

Its working fine for the input text fields, but not for the radio button.

 

I referred the http://developer.force.com/cookbook/recipe/submit-a-form-with-the-enter-key 

 

Attached is my code please help.

<apex:page controller="myCon" sidebar="true">
<script type='text/javascript'>
        function noenter(ev)  {
            if (window.event && window.event.keyCode == 13 || ev.which == 13) {
                doSearchAF();
                return false;
             } else {
                  return true;
             }
         }
    </script>

 <apex:form >
 <apex:pageBlock mode="edit">
            
    <apex:actionFunction name="doSearchAF" action="{!searchJobs}" />
            
       <apex:pageBlockButtons location="bottom">
         <apex:commandButton value="Search Jobs" action="{!searchJobs}" id="mybutton"/>
         <apex:commandButton Value="  Clear  " action="{!cancel}" onclick="return confirmCancel()" />
       </apex:pageBlockButtons>
            
            <apex:pageBlockSection columns="1">
                <apex:pageBlockSectionItem >
                    
                    <apex:outputLabel value="State" for="state" styleClass="textFont"/>                  
                    <apex:inputText value="{!state}" id="state" onkeypress="return noenter(event);" />
                </apex:pageBlockSectionItem>

                <apex:pageblocksectionItem >
                    <apex:outputLabel value="Job Type" for="jt"/>
                    <apex:outputPanel id="jt">
                         <apex:selectRadio value="{!SelectJobType}" onclick="return noenter(event);">
                             <apex:selectOptions value="{!jobType}"/>
                         </apex:selectRadio>
                     </apex:outputPanel>               
                </apex:pageblocksectionItem>            
                
            </apex:pageBlockSection>
       
        </apex:pageBlock>