stewc Posted September 14, 2009 Share Posted September 14, 2009 Hi I have the code below which geocodes a postcode and returns a lat a long value. Its standard code from Google maps. I just want to print these values to a screen. I tried document.write(value) but this produces nothing. Any help would be greatly appreciated. <script type="text/javascript"> var localSearch = new GlocalSearch(); function usePointFromPostcode(postcode) { localSearch.setSearchCompleteCallback(null, function() { if (localSearch.results[0]) { var resultLat = localSearch.results[0].lat; var resultLng = localSearch.results[0].lng; } document.write(resultLat+resultLng); //alert("Latitude: " + resultLat + "\nLongitude: " + resultLng + " q"); }); localSearch.execute(postcode + ", UK"); } </script> TIA Stew Quote Link to comment Share on other sites More sharing options...
Adam Posted September 14, 2009 Share Posted September 14, 2009 document.write() should work, but it's not the method I'd choose. I prefer to edit the 'innerHTML' of a div or span. What happens when you remove the comment for the alert()? Quote Link to comment Share on other sites More sharing options...
stewc Posted September 14, 2009 Author Share Posted September 14, 2009 The document.write doesnt produce anything. The alert part works ok if I remove the comment thats why I dont understand why the document.write doesnt work. How can I print via 'innerHTML'? Quote Link to comment Share on other sites More sharing options...
Adam Posted September 14, 2009 Share Posted September 14, 2009 I posted a link showing how to use innerHTML. I'm not exactly sure why the document.write() method isn't working.. I can't remember the last time I used it to be fair, so I don't know a great deal about it. From the sounds of it though browsers have trouble with it when it's used within XHTML pages, take a look here. I'd say forget about document.write() and learn how to use other methods, namely innerHTML. Quote Link to comment Share on other sites More sharing options...
stewc Posted September 14, 2009 Author Share Posted September 14, 2009 OK, thanks. I will give it a go. Stew Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.