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
afoxmicroedgeafoxmicroedge 

Trigger html form button click event by pressing enter

Hello,

 

I have a html form with a text field and button. When button is clicked some JavaScript is executed that puts the search term in the URL.  I wan't to trigger this button click event by user pressing enter as well...

 

    <script type='text/javascript'> 
        function insertSearchTerm(){
            var searchTerm = document.getElementById("keyword").value; 
            var url="https://c.na11.visual.force.com/apex/portalcasesearch?s="+searchTerm; 
            window.location = url; 
            return false;
        }         
        
    </script>

 

 

      <form name="frmSearch">
          <input type="text" style="width:85%; height:25px;margin:0; padding: 0px 6px 0px;" name="keyword" id="keyword" />
          <input type="button" id="btnSearch" name="btnSearch" value="Search" onclick="insertSearchTerm()"  />
      </form>

 

 

I tried this but I really have no idea what I am doing when it comes to jQuery...

 

    <apex:includeScript value="{!$Resource.Jquery}" />
    <script>

        $j = jQuery.noConflict();
        ("#keyword").keyup(function(event){
            if(event.keyCode == 13){
            jQuery("#btnSearch").click();
            }
        });
    
    </script>