0

I'm using the geocomplete.js API along with the google maps api.

searching for auto complete addresses, suburbs or anything works, and when I press the enter key the fields are auto filled.

My problem is when I try to fire off the enter key programmatically, it doesnt register as the user having pressed enter. so the text boxes dont fill with geolocation details as they normally would if i were to physically press enter.

How can I auto input into the text field and gather the results from the dropdown automatically?

here is the code

<input type="text" id="inputmap" />
    <div id="map"></div>
    <form action="" id="mapform">
        latitude: <input type="text" data-geo="lat" /> <br>
        longitude: <input type="text" data-geo="lng" /> <br>
        Address: <input type="text" data-geo="formatted_address" /> <br>
        Country: <input type="text" data-geo="country" /> <br>
        Country Code: <input type="text" data-geo="country_short" /> <br>
        PCode: <input type="text" data-geo="postal_code" /> <br>
        Locality: <input type="text" data-geo="locality" /> <br>
        Sub-Locality: <input type="text" data-geo="sublocality" /> <br>

    </form> 
    <script>
        $('#inputmap').geocomplete({
            map: '#map',
            details: '#mapform',
            detailsAttribute: "data-geo"
        });


        $(document).ready(function() 
        {
            var e = jQuery.Event("keydown");
            e.keyCode = 50;   

            setTimeout(function()
            {
                $('#inputmap').val("sydney").focus();
            }, 1000);
            setTimeout(function()
            {

                $('#inputmap').trigger(e);  
                alert("pressed");

            }, 3000);


        });




    </script>
happinin
  • 65
  • 8
  • http://stackoverflow.com/questions/832059/definitive-way-to-trigger-keypress-events-with-jquery ? – mplungjan Oct 28 '16 at 09:39
  • seen it, tried it and not working either. also tried waiting 2 seconds after load and to focus. that brings up the auto complete, but when i try to hit enter either way, the enter key doesnt fire off and it stays hanging with the autocomplete open. physical enter pressing works. – happinin Oct 28 '16 at 09:51

0 Answers0