Infowindow with autocomplete textbox

341 views
Skip to first unread message

geom

unread,
Feb 8, 2012, 2:09:34 AM2/8/12
to google-map...@googlegroups.com
I'm trying to use an textfield with autocomplete function in an infowindow in google maps v3.
Is there a way to do so?

Thanks for any help

geom


geom

unread,
Feb 8, 2012, 2:32:29 AM2/8/12
to google-map...@googlegroups.com
I've tried the following, which works fine outside a infowindow. But when I try to apply the autocomplete to a textfield inside an infowindow nothing happens.


//Autosuggest field using FCBKcomplete

$(document).ready(function(){
                $("#sort").fcbkcomplete({
                    json_url: "get_sort_json.php?&fruit="+ document.getElementById('fruit').value+"",
                    addontab: false,
                    maxitems: 20,
                    input_min_size: 1,
                    height: 10,
                    cache: false,
                    newel: false,
                    select_all_text: "select"
                });
            });  
   
//Create form in infowindow to add information to Marker
var html="<form><table><tr><td>Fruit  </td><td><select id='fruit'>"+
                           "<option selected value=''>select fruit</option>"+
                           "<option value='ap'>Apple</option>"+
                           "<option value='pe'>Pear</option>"+
                           "<option value='ch'>Cherry</option>"+
                           "</select></td></tr>"+
            "<tr><td>Sort  </td><td><input type='text'id='sort'/></td></tr>"+
             "<input type='button' value='Save' onclick='saveData()'/></form>";

infowindow = new google.maps.InfoWindow({content: frmhtml});

//Add listener to map, to insert new Marker
google.maps.event.addListener(map, "click", function(event) {
    marker = new google.maps.Marker({
          position: event.latLng,
          map: map,
          draggable: true
        });
    map.setCenter(event.latLng);
    map.setZoom(18) ; 
    google.maps.event.addListener(marker, "click", function() {
          infowindow.open(map, marker);
        });
});



geom

unread,
Feb 9, 2012, 4:48:39 AM2/9/12
to Google Maps JavaScript API v3
I figured out how to get it work.
The problem was, that fields in the infowindow doesn't exit, when the
script is called first.
These objects are created when the infowindow is build, when one
clicks on the marker.

I added the eventhandler onChange = 'getautosuggest()' to the fruit
select into the infowindow and wrapped the creation of the autosuggest
into the function getautosuggest().

Now everything works fine.

Here the parts I've changed:


//Autosuggest field using FCBKcomplete

function getautosuggest(){
$(document).ready(function(){
$("#sort").fcbkcomplete({
json_url: "get_sort_json.php?
&fruit="+document.getElementById('fruit').value+"",
addontab: false,
maxitems: 20,
input_min_size: 1,
height: 10,
cache: false,
newel: false,
select_all_text: "select"
});
});
}

and:


var html="<form><table><tr><td>Fruit </td><td><select id='fruit'
onChange ='getautosuggest()'>"+
"<option selected value=''>select fruit</option>"+
"<option value='ap'>Apple</option>"+
"<option value='pe'>Pear</option>"+
"<option value='ch'>Cherry</option>"+
"</select></td></tr>"+
"<tr><td>Sort </td><td><input type='text'id='sort'/></td></
tr>"+
"<input type='button' value='Save' onclick='saveData()'/></
form>";



Maybe this can help someone else


Georges

Reply all
Reply to author
Forward
0 new messages