1

I have a branch locator script that works when you load it from the same page as the embedded Google map from the Google Maps API, but I can't query it from another page.

The problem is I want to be able to search from the the home page and have the store locator page with the map on it as an action page which then shows the branches as results.

The script is javascript and loads the results from an xml file which has database results in it. I managed to get it to accept a $_GET['search'] string and then load the function that returns the results using the search string.

I can't understand why the results only show when the page is refreshed and not the first time it loads.

<script type="text/javascript">


function getURLParameter(name) {
    return decodeURI(
        (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
    );
}
var urladdress = getURLParameter(name) ;



function initAddress(){


document.getElementById("addressInput").value=urladdress;


searchLocations();return false;

}
 document.ready = initAddress;
</script>
jojojohn
  • 725
  • 2
  • 10
  • 19
  • Read this: http://stackoverflow.com/questions/3698200/window-onload-vs-document-ready – Diodeus - James MacFarlane Jul 11 '13 at 19:26
  • thanks for this, I have ammended the code but still have the same problem although I think you are on the right lines, it is some kind of issue with everything loading in the right order – jojojohn Jul 11 '13 at 21:23

2 Answers2

1

in the end it was solved by delaying the loading of the page with a timer. This allowed the googlemap to load fully before the page is fully loaded

function setAddressInput() {
    document.getElementById("addressInput").value = address;
    setTimeout(function(){searchLocations(); return false;},1000);
}


var address = "";
var pageurl = "http://www.mywebsite.com";

if(address.length) {
        window.onload = setAddressInput;
}
jojojohn
  • 725
  • 2
  • 10
  • 19
0

the name var is undefined when urladdress is set.

Keynan
  • 1,338
  • 1
  • 10
  • 18
  • in know it looks that way but it does somehow manage to retrieve the variable from the url into the form – jojojohn Jul 11 '13 at 22:50