0

Can anybody help me out here.

Im trying to make a page where the user can type in a start location and an end location and on submit I show a map showing the route and the distance.

In my database I have carriers with prices pr. km.

Now I want to show carriers nearby the start or end location and at the same time calculate each carriers Price for the route.

My problem is that I dont know have I can access the distance and use it in the calculation,

Im using Classic asp and access db

I get the distance in the function like this:

document.getElementById("afstand").innerHTML = response.routes[0].legs[0].distance.value;

Isnt there a way so I can save that value like in a global var?

  • Have you already taken a look at this question? http://stackoverflow.com/q/3251609/3915817 If so what part would you say you are unable to do? – KHeaney Jan 21 '15 at 16:00
  • Yes I have seen that but my problem is that I get the distance allright and I can write it on the page as innerhtml, but what I want is to get my hands on that distance so I can use it in my asp to calculate prices – Sanne Faurholt Jan 22 '15 at 10:12
  • You'll need to use javascript to either send a form POST or send it via GET in the querystring to a page. You could also use AJAX to send it to a page depending on what you want to do with it. Remember though, once the ASP has generated and sent the page, there is no further way to interact with it. – Octopoid Jan 22 '15 at 11:22
  • As Octopoid has said there are a variety of ways that you can do this. So to narrow your question a bit you need to select a way that works for your solution. 1) Send the information to a page you can process it on using post or get 2) use an AJAX call to dynamically process it within the page 3) Iterate over the Access information to add it to a JavaScript array and use JavaScript to filter through what you need – KHeaney Jan 22 '15 at 14:29

1 Answers1

0

I tend to use a JavaScript function to post the information to a waiting 'service' in Classic ASP, something like this...

/*
    AJAX extension to allow dynamic interaction between pages.
    This section initialises the variable used to store the XMLHTTP request object.
*/
var xmlhttp;
if (window.XMLHttpRequest) xmlhttp=new XMLHttpRequest();    // code for IE7+, Firefox, Chrome, Opera, Safari...
else xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");      // code for IE6, IE5

/*
    ajaxPage
        Posts a request to the scripted specified page.
    Parameters:
        postPage (string) - The page to be opened.
        paramList (string) - The list of parameters/values to be applied to the page.
    Usage:
        var targetBlock = document.getElementById("resultDiv");
        targetBlock.innerHTML = ajaxPage("resultsPage.asp","calcVal=545")
    Description:
        This routine uses the xmlhttp requesting tools within JavaScript to act as an intermediary between
        script and page.  Specify all paramters in the paramList by separating with an ampersand (&).
*/
function ajaxPage(postPage, paramList) {xmlhttp.open("POST",postPage,false);xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");xmlhttp.send(paramList);return xmlhttp.responseText;}

I would then post the data from the Google Maps calculation to my server page to perform the calcs on.

Paul
  • 4,160
  • 3
  • 30
  • 56