title: How to Check for a missing variable In JS?
body: <p>I am trying to check if a variable exists before allowing the form to submit. </p>
  
  <p>Currently, the user enters the address into the form and autocomplete adds lat and long to the form. I wrote the following js</p>
  
  <pre><code>function check() {
      let latitude = document.getElementById("latitude").value;
      if (latitude == null) {
          window.prompt("ned a correct address", "");
          return false;
      } else {
          alert('It worked');
          return true;
      }
  }
  </code></pre>
  
  <p>When I submit an address that doesn't have the lat and long autocompleted I am still getting "it worked"</p>
  
  <p>Here is my form</p>
  
  <pre><code>&lt;form method="GET" action="/search" onsubmit="check()"&gt;
      &lt;input class="form-control" id="getaddy" type="text" placeholder="Search..." name="term" onFocus="geo()"&gt;
      &lt;input id="latitude" type="hidden" name="latitude"&gt;
      &lt;input id="longitude" type="hidden" name="longitude"&gt;
  &lt;/form&gt;
  </code></pre>