1 Reply Latest reply on Nov 7, 2011 9:22 AM by mcmurdosound

    a4j:ajax event for submit or enter keyboard

    bouz78

      Hello there,

       

      I use the following to be able to filter entry from an inputText. It works fine when i use the tab button. However, I want it also to respond when I hit the enter button on keyboard

       

      <a4j:ajax event="change" render=... execute...>

       

       

       

       

      best regards

        • 1. Re: a4j:ajax event for submit or enter keyboard
          mcmurdosound

          I usually use something like this:

           

          <h:inputText  id="quickSearch"

                value="#{myManager.searchString}"          

                onkeypress="doSearch(event)"

            />

          <h:commandLink id="doSearchLink"

                value="search"                                                                  

                action="#{myManager.search}"

                />

           

          <script type="text/javascript">

                function doSearch(event){         

                  // on enter: start search

           

                  if (event.which == "13") {

                      event.preventDefault();

                      document.getElementById('form:doSearchLink').click();

                  }

                }

             </script>

           

          this works in Firefox. For IE you have to use another "event" event and other properties.

           

          Instead of a h:commandLink you could call an a4j:jsFunction