title: Javascript:Block form submit on Enter Key press
body: <p>I have a web page where i have 2 forms when i click the enter key, I am calling a javascript function to force the page to load another page.My code is </p>
  
  <pre><code>function SearchUser()
  {
  var text = document.getElementById("searchItem").value;
  text = text == "" ? -1 : text;
  var by = document.getElementById("listBy").value;   
  var on="";
  if(by==1)
  {
      on="USERNAME";
  }
  else if(by==2)
  {
      on="FIRSTNAME";
  }
  else if(by==3)
  {
      on="EMAIL_ID";
  }
  
  gotoUrl="userlist.php?searchItem="+text+"&amp;onSearch="+on; 
      alert(gotoUrl); 
  window.navigate=gotoUrl;
  </code></pre>
  
  <p>}</p>
  
  <p>and</p>
  
  <pre><code>$(document).ready(function()
  {
   $("#frmUserListSearch").keyup(function(event)
   {
    if(event.keyCode == 13)
    { 
      SearchUser();
    }
   });
  </code></pre>
  
  <p>});</p>
  
  <p>But the page is doing a form submit when the SearchUSer function being called.I am getting the correct url in the alert.But The page is not loading  in the brower</p>
  
  <p>Any Ideas ???</p>
  
  <p>Thanks in advance</p>