javascript - Autocomplete jQueryUI double call function on select and press enter -


i'd little help. here's jsfiddle : https://jsfiddle.net/mirawen/q59nqh2z/

function keypress(keyevent) {     if (keyevent.which == 13)     mainfunction(); }  function mainfunction() {   alert("hello world"); }  var arrsource = ["foo", "foooo", "foooooo", "bar", "barr", "barr"];  $(document).ready(function() {   $("#txtsearch").autocomplete({     source: arrsource,     minlength: 1,     select: function (event, ui)     {       mainfunction();      }   }); }); 

when press enter, want call mainfunction(), , call function when select item autocomplete point is, when select item , press enter, mainfunction() called twice.
don't know how solve this.

thanks answers !

i think calling same function twice on same event,so calling main function twice. if press enter keypress/keyup/keydown event. so, when document ready, getting called once , gets called on enter keypress event.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -