title: Redirecting page from form with addEventListener() method
body: <p>I am trying to get an input value from a form to redirect to the user to a new page. The environment is in Sharepoint Online. </p>
  
  <p>I can't use HTML events (i.e. onclick or onkeypress), which is why I decided to use event listeners instead. </p>
  
  <p>I have tested the code locally and know that it would work with the above-mentioned events, but I was asked to remove them in order to prevent XSS type attacks.</p>
  
  <p>I tried using event listeners but can't seem to get it to work the way I want it should. </p>
  
  <p>HTML code:</p>
  
  <pre><code>&lt;form method="get" action="" class="search-container"&gt;
        &lt;input id="search-input" type="text" placeholder="Search..."&gt;
        &lt;a class="material-icons" id="search-submit" &gt;search&lt;/a&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>JS code:</p>
  
  <pre><code>document.getElementById('search-input').addEventListener('keypress', searchKeyPress)
  
  function searchKeyPress(e) {
    e = e || window.event;
    if (e.keyCode === 13)
    {
        document.getElementById('search-submit').click();
        //alert('Enter Pressed')
        return false;
    }
    return true;
  }
  
  document.getElementById('search-submit').addEventListener('click', redirect)
  
  // redirect function
  function redirect() {
    //look for search id
    var item = document.getElementById("search-input").value;
  
    // alert(item)
  
    //redirect page
    alert('Search Icon Clicked')
    window.location.href = "https://domain.sharepoint.com/sites/Intranet/_layouts/15/osssearchresults.aspx?u=https%3A%2F%domain%2Esharepoint%2Ecom%2Fsites%2FIntranet&amp;k=" + item + "&amp;ql=1036";
  
  }
  </code></pre>
  
  <p>I expect to be able to redirect to the page that is in the 
  <code>window.location.href</code>, but the page refreshes instead.</p>
  
  <p>Any help would be appreciated.</p>