JQuery Autocomplete: Submit Form on selection?

前端 未结 5 1658
后悔当初
后悔当初 2020-12-24 12:50

Using JQuery Autocomplete on a traditional HTML form.

Trying submit the form (the old-fashioned way) when a selection is made.

But the input box gets filled

5条回答
  •  半阙折子戏
    2020-12-24 13:53

    $( "#searchField" ).result(function(event, data, formatted) {
      $(this).closest("form").submit();
    });
    

    The searchField is already populated with the selected field, so no need to do it in this function again.

    Official documentation: http://docs.jquery.com/Plugins/Autocomplete/result#handler

提交回复
热议问题