Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem in Javascript Code without using alert

    Hi,
    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


    <html>
    <head>
    <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) {
    //alert(google.maps.GeocoderStatus.OK);
    alert(res[1].address_components.postal_code);
    alert('testing');
    if (status==google.maps.GeocoderStatus.OK) {

    //alert(res[0].address_components.postal_code);
    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);
    //alert(p);
    if(array1==null)
    array1 = p;
    else
    array1 = array1 + p + ';';
    // alert(array1);

    if (res[1]) {

    //alert(res[1].formatted_address);
    } 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;

    //alert(s);
    var la =s.lat();
    var ln =s.lng();
    //alert(la);
    //alert(ln);
    geo = new google.maps.Geocoder();
    //alert(la+','+ln);
    codeLatLng(la,ln);
    //window.setTimeout('function(){alert("Hello")}',200);
    //timeout_init(la,ln);
    }

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

    google.maps.event.addDomListener(window, 'load', initialize);
    </script>
    </head>

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

    </html>

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,947
    Thanks
    79
    Thanked 4,424 Times in 4,389 Posts
    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:

    Replace
    Code:
        alert( whatever );
    with
    Code:
        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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Quote Originally Posted by soni@123 View Post
    Hi,
    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.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,947
    Thanks
    79
    Thanked 4,424 Times in 4,389 Posts
    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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,
    Can you help me how to make code synchronous or how to resolve that problem?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •