title: typeerror when running a fetch function before form submission
body: <p>I got this <strong>error</strong>:</p>
  <pre><code>TypeError: NetworkError when attempting to fetch resource
  </code></pre>
  <p>when trying to run <code>*geocodeAddress*()</code>.</p>
  <p>If I run the same exact code outside of that function without <code>onsubmit=&quot;&quot;</code>, it works and logs the data to the console. Why is this?</p>
  <pre><code>&lt;?php 
  
  // ...
  
  ?&gt;&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;script type=&quot;text/javascript&quot; src=&quot;js/maps.js&quot;&gt;&lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;form name=&quot;info&quot; action=&quot;private/database.php&quot; method=&quot;POST&quot; onsubmit=&quot;return geocodeAddress()&quot;&gt; 
        &lt;input type=&quot;text&quot; name=&quot;surname&quot; placeholder=&quot;性氏&quot; required&gt;&lt;br&gt;
        &lt;input type=&quot;text&quot; name=&quot;given_name&quot; placeholder=&quot;名字&quot; required&gt;&lt;br&gt;
        &lt;label for=&quot;male&quot;&gt;
          &lt;input type=&quot;radio&quot; id=&quot;male&quot; name=&quot;gender&quot; required&gt;
          男性
        &lt;/label&gt;
        &lt;label for=&quot;female&quot;&gt;
          &lt;input type=&quot;radio&quot; id=&quot;female&quot; name=&quot;gender&quot;&gt;
          女性
        &lt;/label&gt;&lt;br&gt;
        &lt;input type=&quot;text&quot; name=&quot;email&quot; placeholder=&quot;電子信箱&quot; required&gt;&lt;br&gt;
        &lt;input type=&quot;text&quot; name=&quot;phone_number&quot; placeholder=&quot;電話&quot; required&gt;&lt;br&gt;
        &lt;input type=&quot;text&quot; id=&quot;address&quot; name=&quot;address&quot; placeholder=&quot;地址&quot; required&gt;&lt;br&gt;
        &lt;input type=&quot;hidden&quot; name=&quot;latlng&quot;&gt;
        &lt;input type=&quot;date&quot; name=&quot;cleaning_date&quot; required&gt;&lt;br&gt;
        &lt;input type=&quot;submit&quot; name=&quot;form_submit&quot;&gt;
  
        &lt;script&gt;
          function geocodeAddress() {
            fetch('https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&amp;key=AIzaSyDxn8WYv2aE5UrrufXLqeXKVYUnD-VyReA')
              .then(res =&gt; res.json())
              .then(data =&gt; console.log(data))
              .catch(error =&gt; console.log(error));
          }
      &lt;/script&gt;
      &lt;/form&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>