0

I added autocomplete places to a google map and have a FROM and TO input fields. The TO input has a fixed value, when the users choose an address from the suggestions and press the TAB or ENTER key it submit the route and works fine!

But when the user click on a suggestion, it doesn't show the route. How can I handle the place_changed as a enter OR tab key?

The code in HTML:

    <div id="controls">
  <label><span>Van:</span> <input class="test" id="vertrek" type="text" name="from"></label>
  <label><span>Naar:</span> <input type="text" id="bestemming" name="to" readonly></label>
</div.

In JavaScript I tried this:

  google.maps.event.addListener(autocomplete, 'place_changed', function() {
     document.getElementById("vertrek").focus();
     return false;
   });

It doesn't work, I don't know why because when I add a window.alert and select an item from the suggestion list it shows the alert.

I also tried to put the input fields in a form tag and change the .focus to .submit, it doesn't work also.

Shortly: I want to make it possible to handle the click on the suggestion list as a keypress (tab OR enter)

Hnry Cn
  • 29
  • 1
  • 9
  • Can u show some demo for better understanding? – Vinay Oct 26 '16 at 17:09
  • @Novice http://codepen.io/anon/pen/BLbYzA when you type a adress and push enter or tab it calculate a price, but when you select/click the adress from the suggestion it doesn't calculate – Hnry Cn Oct 29 '16 at 10:50
  • Please try using `autoFocus:true` together with `.keypress` as event listener as given in this [SO post](http://stackoverflow.com/questions/25449399/jquery-autocomplete-submit-form-on-select-item-button-click-and-or-enter). You may also try the suggested solution in [Google Places Autocomplete - Pick first result on Enter key?](http://stackoverflow.com/questions/14601655/google-places-autocomplete-pick-first-result-on-enter-key) Hope that helps! – Teyam Oct 30 '16 at 10:56

1 Answers1

0

I didn't change anything.. The code works now, I think the api was overloaded that it doesn't work when I ask the question.

Hnry Cn
  • 29
  • 1
  • 9