Hello, I have the following code function geo(){ navigator.geolocation.getCurrentPosition(showPosition); } function showPosition(position){ document.getElementById("HIDDENlatitude").style.display = ""; document.getElementById("HIDDENlongitude").style.display = ""; document.getElementById("GEOlatitude").innerHTML = position.coords.latitude; document.getElementById("GEOlongitude").innerHTML = position.coords.longitude; return GETnumber(); return GETstreet(); } function GETnumber(){ var xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET", "/mods/latlng.php?lat="+position.coords.latitude+"&long="+position.coords.longitude+"&number", true); xmlhttp.send(); document.getElementById("addressnumber").value = xmlhttp.responseText; } function getPAGE(){ var GETstreet = new XMLHttpRequest(); xmlhttp.open("GET", "/mods/latlng.php?lat="+position.coords.latitude+"&long="+position.coords.longitude+"&street", true); xmlhttp.send(); document.getElementById("addressstreet").value = xmlhttp.responseText; } PHP: GETnumber and GETstreet don't seem to work. Can anyone please help?
Your code is very difficult to read. Please include some newlines, otherwise I can't read it. If you use AJAX, try a library like jQuery or Prototype. And to debug JS code, use the developer toolkit by chrome (press f12 in chrome). It gives you JS errors.
From what I can tell, you have the statement "return GETnumber();" twice, one after the other. Remove one.
You have return GETnumber(); return GETstreet(); You can only return a single value. You can cheat by creating 2 global variables (declare them outside any function) and set them equal to the 2 functions (one variable for each function), then return; Then your number and street variables will be available to your other code. (showPosition is a callback function - don't return things with it.) I'd also base all this code on if (navigator.geolocation){ } If the user's computer doesn't do geolocation, your code won't barf.
Rukbat's right -- first thing I noticed... you can only return ONE value. Once you say return... it, well, RETURNS -- anything AFTER return is never run! Though since NEITHER function is actually returning a value, why are you calling them via RETURN? It's also helpful to make sure that you define a function in the code BEFORE you call it -- so your source order in addition to being an illegible mess due to a lack of carriage returns, is also in the wrong order. I would also advise against making functions for things that have a single call inside them -- the overhead of an extra function call typically outweighs any advantages you might think you are getting in code size from functions like your geo() one. Probably also not a good idea to be messing around with STYLE in your scripting, since that's CSS job -- at which point swap a class on a parent element to make styling easier in the long run. Also, without seeing the markup this is being run atop, the scripting is pretty much meaningless gibberish to us.