title: Changing input value via Javascript before form submission? PHP
body: <p>Been through a number of questions and nothing seems to work for my case.</p>
  
  <p>Okay so, I have a form with a single input (search) field and a submit button. When the user enters a value (an address in this case) and hits submit, that address value needs to be sent to a JavaScript function which converts it into Longitude and Latitude values, and then these coordinates need to be sent to the destination page instead of the address they input. </p>
  
  <p>Here is my code so far:</p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;form name="searchform" action="required/results.php" method="get" id="searchbar" onsubmit="convertToCoords()"&gt; 
      &lt;input type="text" name="input" id="address" placeholder="Search an address or suburb..."&gt;
      &lt;input type="submit" class="searchbtn" value="Search"&gt; 
  &lt;/form&gt; 
  </code></pre>
  
  <p><strong>JS</strong></p>
  
  <pre><code>function convertToCoords() {    
      var address = document.getElementById("address").value; // Get the input address from the textbox
  
      /* Address to Coordinates conversion (Disregard) */
      geocoder = new google.maps.Geocoder(); 
      geocoder.geocode( { 'address': address}, function(results, status) {    
      if (status == google.maps.GeocoderStatus.OK) {
  
          // Get the Lat. and Long. 
          var searchedLat = results[0].geometry.location.lat();
          var searchedLong = results[0].geometry.location.lng();
  
          // Set address input value to coordinates, then submit form
          document.getElementById('address').value = searchedLat + ',' + searchedLong;
          document.getElementById('searchbar').submit();
  
      } else {
        alert("Geocode was not successful for the following reason: " + status);
      }
      }); 
  }
  </code></pre>
  
  <p><strong>PHP on destination page (for testing)</strong></p>
  
  <pre><code>&lt;?php 
      if (isset($_GET['input'])) {
          echo $_GET['input']; // get value of search input
      }
  ?&gt;
  </code></pre>
  
  <p>So at the moment what is happening is it is just echoing the address they input, no conversion happens.</p>
  
  <p>I don't know (or care) when the conversion should happen, e.g. whether it should happen before submission or after.</p>
  
  <p>Thanks for any feedback!</p>