Note that there are some explanatory texts on larger screens.

plurals
  1. POStore value in URL with keeping the original values in browser
    text
    copied!<p>So I'm creating am ASP.net page using JavaScript to calculate distance between two zipcodes. after submitting the form, the page shows both addresses and the distance. However, I want to use these values in ASP.NET so I stored the distance in the URL so i can call it with a .net label but when I do so, and since it has to go back to the server, it refreshes the page and deletes the JavaScript calculated values! I want to store the distance in URL in addition to keep the calculated values on page. Here is what I have now </p> <pre><code>var geocoder, location1, location2; function initialize() { geocoder = new GClientGeocoder(); } function showLocation() { geocoder.getLocations(document.forms[0].address1.value, function (response) { if (!response || response.Status.code != 200) { alert("Sorry, we were unable to geocode the first address"); } else { location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address}; geocoder.getLocations(document.forms[0].address2.value, function (response) { if (!response || response.Status.code != 200) { alert("Sorry, we were unable to geocode the second address"); } else { location2 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address}; calculateDistance(); } }); } }); } function calculateDistance() { try { var glatlng1 = new GLatLng(location1.lat, location1.lon); var glatlng2 = new GLatLng(location2.lat, location2.lon); var miledistance = glatlng1.distanceFrom(glatlng2, 3959).toFixed(1); var kmdistance = (miledistance * 1.609344).toFixed(1); document.getElementById('results').innerHTML = '&lt;strong&gt;Address 1: &lt;/strong&gt;' + location1.address + '&lt;br /&gt;&lt;strong&gt;Address 2: &lt;/strong&gt;' + location2.address + '&lt;br /&gt;&lt;strong&gt;Distance: &lt;/strong&gt;' + miledistance + ' miles (or ' + kmdistance + ' kilometers)'; //+ '&lt;br /&gt;&lt;strong&gt;HiddenField &lt;/strong&gt;' + miledistance; var loc = self.location.href; window.location.href = loc+"?D="+miledistance; } catch (error) { alert(error); } } &lt;/script&gt; </code></pre> <p> </p> <p></p> <pre><code>&lt;form action="#" onsubmit="showLocation();return false;"&gt; &lt;p&gt; &lt;input type="text" name="address1" value="45419" class="address_input" size="40" /&gt; &lt;input type="text" name="address2" value="47714" class="address_input" size="40" /&gt; &lt;input type="submit" name="find" value="Search" /&gt; &lt;/p&gt; &lt;/form&gt; &lt;p id="results"&gt;&lt;/p&gt; &lt;form id="form1" runat="server"&gt; &lt;div&gt; &lt;asp:Label ID="Label3" runat="server"&gt;&lt;/asp:Label&gt; &lt;br /&gt; &lt;asp:Label ID="Label2" name="address1" value="Address 1" class="address_input" size="40" runat="server"&gt;&lt;/asp:Label&gt; &lt;br /&gt; &lt;asp:Label ID="Label1" runat="server"&gt;&lt;/asp:Label&gt; &lt;br /&gt; &lt;br /&gt; &lt;asp:Button ID="Button1" runat="server" PostBackUrl="~/Size.aspx?a='miledistance'" Text="Next" /&gt; &lt;/div&gt; &lt;/form&gt; </code></pre> <p></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