View Full Version : Problem in Javascript Code without using alert

06-28-2012, 01:09 PM
I am facing problem when i am not using alert in javascript. If i use alert then script is executing otherwise script is not executing and i don't want alert in script. Please help me

script is given below

<script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script>
<script type="text/javascript" src="https://maps-api-ssl.google.com/maps/api/js?v=3&sensor=true&libraries=places"></script>
<script type="text/javascript">
var array1;
var map;
var infowindow;
var lat = 40.5998;
var lng = -74.5542;
var geo;
function initialize() {
var pyrmont = new google.maps.LatLng(lat, lng);
map = new google.maps.Map(document.getElementById('map'), {
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: pyrmont,
zoom: 15

var request = {
location: pyrmont,
radius: 120000,
types: ['store']
geo = new google.maps.Geocoder();

var service = new google.maps.places.PlacesService(map);
service.search(request, callback);

function codeLatLng(la,ln){
var lat = parseFloat(la);
var lng = parseFloat(ln);
var latlng = new google.maps.LatLng(lat,lng);
geo.geocode({'latLng': latlng}, function(res, status) {
if (status==google.maps.GeocoderStatus.OK) {

var a=res[1].formatted_address;
var u=a.indexOf(",");
var n= a.lastIndexOf(",");

var t = a.substring(u,n);

var l = t.substring(t.lastIndexOf(","),t.length);
var p = l.substring(4,l.length);
array1 = p;
array1 = array1 + p + ';';
// alert(array1);

if (res[1]) {

} else {
//alert("No results found");
} else {
// alert("Geocoder failed due to: " + status);


function timeout_init(la,ln) {
setTimeout('codeLatLng(la,ln)', 200);
function callback(results, status) {
var geocoder;
var map;
var infowindow = new google.maps.InfoWindow();
var marker;
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
var s=results[i].geometry.location;

var la =s.lat();
var ln =s.lng();
geo = new google.maps.Geocoder();

var url = '/apex/searcheventvf2?city=' + array1;
window.open(url, '_self', 'width=400,height=200');

google.maps.event.addDomListener(window, 'load', initialize);

<div id="map" style="display:none"></div>


Old Pedant
06-28-2012, 09:28 PM
If the alert isn't working, it is probably because you are trying to alert an expression that is causing an error.

One way to find out:


alert( whatever );


try {
alert( whatever );
} catch ( e ) {
alert( "Attempt to alert 'whatever' caused error" );

But even better would be to simply use a debugger and let it catch the error and tell you what the error is.

Logic Ali
06-28-2012, 10:30 PM
I am facing problem when i am not using alert in javascript. If i use alert then script is executing otherwise script is not executing

I'm not familiar with that API, but the usual cause of that problem is running an asynchronous procedure but failing to wait for the result before continuing.

Old Pedant
06-28-2012, 11:13 PM
Oh, I see what you are saying! I thought he meant that the alert, per se, wasn't showing what he expected. DOH on me.

06-29-2012, 06:26 AM
Can you help me how to make code synchronous or how to resolve that problem?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum