Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript Onchange Event In the form (Getting Latitude And Longitude from Postcode)
    text
    copied!<p>What I'm trying to do is to get the latitude and longitude from imported postcodes. Which works fine as long as I stick to only one input (first or second separate). I can't get it to work once I try with both of them. I'm using the onchange event ..</p> <p>Please take a look at the form:</p> <pre><code>&lt;form name="latlon" action="test2a.php" method='post' onchange="return usePointFromPostcode(document.getElementById('postcode').value) &amp;&amp; usePointFromPostcode1(document.getElementById('postcode1').value) "&gt; &lt;input id="postcode" type="text" size="10" /&gt;&lt;br&gt; &lt;input id="postcode1" type="text" size="10"/&gt;&lt;br&gt; Latitude:&lt;input name="lat" type="text" id="lat" size="10"/&gt;&lt;br /&gt; Longitude:&lt;input name="lon" type="text" id="lon" size="10"/&gt;&lt;br&gt;&lt;br&gt; Latitude:&lt;input name="lat1" type="text" id="lat1" size="10"/&gt;&lt;br /&gt; Longitude:&lt;input name="lon1" type="text" id="lon1" size="10"/&gt; &lt;input type="submit" value="Get Lat / Lon"/&gt; &lt;/form&gt; </code></pre> <p>and in JavaScript this is what I used to get latitude and longitude:</p> <pre><code>function usePointFromPostcode(postcode, callbackFunction) { localSearch.setSearchCompleteCallback(null, function () { if (localSearch.results[0]) { var resultLat = localSearch.results[0].lat; var resultLng = localSearch.results[0].lng; var point = new GLatLng(resultLat, resultLng); document.forms['latlon'].lat.value = resultLat; document.forms['latlon'].lon.value = resultLng; callbackFunction(point); } else { alert("Postcode not found!"); } }); localSearch.execute(postcode + ", UK"); } function usePointFromPostcode1(postcode1, callbackFunction) { localSearch.setSearchCompleteCallback(null, function () { if (localSearch.results[0]) { var resultLat = localSearch.results[0].lat; var resultLng = localSearch.results[0].lng; var point = new GLatLng(resultLat, resultLng); document.forms['latlon'].lat1.value = resultLat; document.forms['latlon'].lon1.value = resultLng; callbackFunction(point); } else { alert("Postcode not found!"); } }); localSearch.execute(postcode1 + ", UK"); } </code></pre> <p>I'm totally stuck here. What am I doing wrong? Will appreciate any help and thank you in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload