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 Link to comment https://forums.phpfreaks.com/topic/174165-help-with-printing-to-screen/ 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()? Link to comment https://forums.phpfreaks.com/topic/174165-help-with-printing-to-screen/#findComment-918131 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'? Link to comment https://forums.phpfreaks.com/topic/174165-help-with-printing-to-screen/#findComment-918136 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. Link to comment https://forums.phpfreaks.com/topic/174165-help-with-printing-to-screen/#findComment-918144 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 Link to comment https://forums.phpfreaks.com/topic/174165-help-with-printing-to-screen/#findComment-918148 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.