Moncho Chavez
Moncho Chavez

Reputation: 694

action on page load to set marker on Google Maps probs

Hi I have an input where the user insert his address and after that when he click outside of the input a marker for the map is set.. THIS WORKS GREAT.

NOTE: IM setting marker on google maps..

$("#address1").blur(function()
        {
            loadCoordinates("");
        });

the problem is... When a user use the edit form.. wich uses the same javascript for set the marker... they need to click in the ipnut and then outside to set the marker

So i try to set the marker on document.load But this is not setting any marker on my map..

$(document).ready(function(){
var checkVal = $("#address1").val();
if(checkVal==''){

}
else{
loadCoordinates("");
}
});

EDIT:

I even tried this :( also

$(function()
        {
            loadCoordinates("");
        });

Not working..

Upvotes: 0

Views: 112

Answers (2)

helion3
helion3

Reputation: 37391

Based on your comment it sounds like you need two different events to trigger the map load. There are a few choices based on your existing design, you're pretty close:

function loadCoordinates(){
  if( $("#address1").val() != '' ){ 
    // do the actual map pin load
  }
}
$(function(){

  // Load the coords on doc load
  loadCoordinates();

  $("#address1").blur( loadCoordinates );

});

Or, you could technically just call $("#address1").blur( loadCoordinates ).trigger('blur');

Upvotes: 2

Vladimirs
Vladimirs

Reputation: 8599

Blur event triggers when your element lost focus, if you want invoke your function earlier better to use keyup but in that case you also need to check if current input value is valid for your function because keyup event triggered when user releases a key on the keyboard.

Upvotes: 0

Related Questions