Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Stop the warning box appearing!
Old 01-19-2010, 12:12 PM Stop the warning box appearing!
rolda hayes's Avatar
Wannabe Adventurer...

Posts: 961
Name: Darren
Location: England
Trades: 0
Hi I'm using this code to run a dealer locator.

When the search page is loaded, it pops open a browser warning window stating that no postcode has been entered...

Can this be removed so the page does nothing until the user searches for something!

I'm assuming that it is around here somehwhere,
Code:
 $.each(data, function(i, item) {
                        if (item.error == 'none') {
                            alert('No results found or Postcode incorrect');
                            $('#error').append('No results found or Postcode incorrect');
                            flag = false;
                            return false;
                        }
But not to sure how to remove it without it killing the page.

Cheers,


Code:
$(document).ready(function() {
    var mark;
    var pointA;
    var pointB;
    if (GBrowserIsCompatible()) {
        var m = $("#map1")[0];
        if(m) {		
            var map = new GMap2(m);
            var start = new GLatLng(51.49699,-3.17651);
            var zoomLevel = 7;
            map.setCenter(start, zoomLevel);
            map.addControl(new GSmallMapControl());
 
            GEvent.addListener(map, 'click', function(overlay, point){
                if(mark) {
                    map.removeOverlay(mark);
                }
                if(point) {
                    pointA = new GPoint(point.x, point.y);
                    mark = new GMarker(pointA);
                    map.addOverlay(mark);
                    map.getCenter(point);
                    $('#lng').attr('value',point.x);
                    $('#lat').attr('value',point.y);
                }
            });
            $('#city').change(function(){
                var district = 'district='+$(this).val();
                $.ajax({
                    type: 'POST',
                    data: district,
                    url: 'map_district.php',
                    success: function(r) {
                        var cord = r.split("|");
                        if(mark) {
                            map.removeOverlay(mark);
                        }
                        pointB = new GLatLng(cord[0],cord[1]);
                        mark = new GMarker(pointB);
                        map.addOverlay(mark);
                        map.setCenter(pointB, 14);
                        $('#lat').attr('value',cord[0]);
                        $('#lng').attr('value',cord[1]);
                    }
                });
            });
        }
    }
});

$(document).ready(function() {  
		var mapContainer = $('#map3')[0];
	if (GBrowserIsCompatible()) {
		if (mapContainer) {
			var map = new GMap2(mapContainer);
			map.addControl(new GLargeMapControl);
			//coords here are default map setting
      map.setCenter(new GLatLng(53.49699,-1),6);
    

      var zip = $('#zip').val();
  		var radius = $('#radius').val();
				zip = zip.replace(/ /, "");
				if (zip == '') {
					alert("You need to provide a PostCode"); return;
				}
				var rand = new Date().getTime();
				$.getJSON('_postcode.php?search=s&rand=' + rand, { zip: zip, radius: radius }, function(data) {
	                var markers = [];
	                var descriptions = [];
		              var balloons = [];
	                var bounds = new GLatLngBounds();
                  
                 function joe(point)
                 {
	                 var marker = new GMarker(point,icon);
                   var blueIcon = new GIcon(G_DEFAULT_ICON);
                   blueIcon.image = "./images/blue-dot.png";
                   blueIcon.iconSize = new GSize(32,32)
                   markerOptions = { icon:blueIcon };
                   var point0 = new GLatLng(oLat, oLng);
                   var marker0 = new GMarker(point , markerOptions);
                   markers[0] = marker0;
                   descriptions[0] = '<div class="branch">Your location</div>';
                   balloons[0] = '<div class="branch">You are here</div>';
                   map.addOverlay(marker0);
                   bounds.extend(point0);
                   GEvent.addListener(marker0, 'click', function() {
                   marker0.openInfoWindowHtml('<div class="branch_balloon">You are here</div>');
                   });
	                 map.addOverlay(marker0);
                 }
      
                //set up 'You are here marker'
                var localSearch = new GlocalSearch();
                usePointFromPostcode(zip, joe);

                    map.clearOverlays();
                    $('#error').html('');
                    $('#locations').html('');
                    $('#closest_location').html('');
                    var flag = true;

                    $.each(data, function(i, item) {
                        if (item.error == 'none') {
                            alert('No results found or Postcode incorrect');
                            $('#error').append('No results found or Postcode incorrect');
                            flag = false;
                            return false;
                        }

                    	
						   var description =
					

                             '<div class="branch ui-corner-left ui-corner-right" id="' + item.user_id + '">' +
                            '<div class="branch_image_holder"><a href="./viewprofile.php?id=' + item.user_id + '"><img class="branch_image ui-corner-left ui-corner-right" src="view_image.php?image_id=' + item.profile_image + '"/></a></div>' +
                            '<div class="b_right"><div class="branch_name"><a href="./viewprofile.php?id=' + item.user_id + '">' + item.business_name + '</a></div><div class="branch_distance">Approximately ' + item.distance + ' Miles</div>' +
                            
							'<div class="branch_add1">' + item.business_address_1 + '</div>' +
							'<div class="branch_add2">' + item.business_address_2 + '</div>' +
							'<div class="branch_town">' + item.business_address_3 + '</div>' +
							
							
							
							
							'<div class="branch_postcode">' + item.business_postcode + '</div>' +
                          //  '<div class="branch_description">' + item.business_description + '</div>' +//
                            '<div class="branch_website"><a target="_blank" href="http://' + item.business_website + '">' + item.business_website + '</a></div></div>' +
							
							
							
							
                            '<div class="branch_show" id="' + (i+1) + '"><a href="#map3">Show on map</a></div></div>';
                        
					
						var balloon =
                            '<div class="branch_balloon">' +
                            item.business_name + ' (~ ' + item.distance + ' m)<br />' + item.business_postcode + ' <br />' +
                            '<span><a href="#' + item.user_id + '">Find entry</a><br />' +
                            '<span><a href="./viewprofile.php?id=' + item.user_id + '">Go to Profile Page</a></div>';
                        var lat = item.latitude;
                        var lng = item.longitude;
                        oLat = item.oLat;
                        oLng  = item.oLng;
                        //hacking in the source of search
                        if(i == '0'){
                          
                        }
                        var point = new GLatLng(lat, lng);
                        var marker = new GMarker(point);
                        markers[i+1] = marker;
                        descriptions[i+1] = description;
                        balloons[i+1]     = balloon;
                        $('#locations').append(description);
                        map.addOverlay(marker);
                        bounds.extend(point);
                        GEvent.addListener(marker, 'click', function() {
                           marker.openInfoWindowHtml(balloon);
                        });
                    });

                    $('#closest_location').append(descriptions[1]);
                    
                    //add in some fuzzy zoom - basically if the radius we are looking at is > 20miles then go to a larger zoom frame
                    if(radius > 20)
                    { z = 12; }
                    else
                    { z = 13; }
					
                    map.setZoom(z);
                    // just in case we did not find anything
                    if (!flag)
                        map.setCenter(new GLatLng(53.49699,-1),6);

                    else
                    {
                       map.setCenter(new GLatLng(oLat,oLng),z);
                       //this will set the viewport to center of all markers found
                       //map.setCenter(bounds.getCenter());
                    }

                    $('.branch_show').click(function() {
                        var id = $(this).attr('id');
                        markers[id].openInfoWindowHtml(balloons[id]);
                    });
				});
			
		}
	}
});
__________________
I Just a test to see what happens...
Please login or register to view this content. Registration is FREE

"Let us be thankful for the fools. But for them the rest of us could not succeed..."
rolda hayes is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Reply     « Reply to Stop the warning box appearing!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.09679 seconds with 12 queries