title: My code to capture the submit button on a form works but am I doing it correctly?
body: <p>I have an HTML form and some JavaScript code below it.  Everything works.  But what bothers me is that while everything else is in a function, the way I capture the submit button is not in a function.</p>
  
  <p>So am I doing this correctly?</p>
  
  <p>My form:</p>
  
  <pre><code>&lt;form autocomplete="off" action="/cgi-bin/prl.pl"&gt;
  &lt;div class="autocomplete" style="width:300px;"&gt;
  &lt;input id="myInput" type="text" name="myCountry" placeholder="Pick a country" autofocus&gt;
  &lt;input id="113" type="submit" value="Ok"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>The top of my scripts:</p>
  
  <pre><code>&lt;script&gt;
  
  var form = document.querySelector("form");
  
  form.addEventListener("submit", function(e) 
  {
    //////insert code to validate that 
    //////specific data is in my form
  
    e.preventDefault();
  });
  
  function setFocusToInput()
  {
      var textbox = document.getElementById("myInput");
      textbox.focus();
  }
  
  function autocomplete(inp, arr) 
  {
    var currentFocus;
  </code></pre>