1

I have a handful of fields:

 <input type='text' id='field1' name='field1' class='checkMe'>
 <input type='text' id='field2' name='field2' class='checkMe'>
 <input type='text' id='field3' name='field3' class='checkMe'>

I have a jquery autocomplete function:

 $('#someField').autocomplete({
       /// options
       $.ajax({
           ////
           success:function(result){
                 $.each(result,function(e,i){
                      $('#'e).val(i);
                      // -- e is a valid id of a text field

                 });
           }
       });
 });

the autocomplete part works fine. I also have another event listener for those fields:

  $('.checkMe').bind('keyup change', function () {
      alert('hi');
          //do something
  });

Users on this page can either fill out form by entering values in each field, or selecting a field somewhere else and let autocomplete fill out form.

Problem: When user enters data manually, .checkMe fires correctly, When user uses autocomplete, the .checkMe event never fires.

bart2puck
  • 2,432
  • 3
  • 27
  • 53
  • 2
    you need to trigger yourself, `val` does not, [see here](https://stackoverflow.com/a/3179392/7393478) – Kaddath Mar 26 '19 at 13:01

1 Answers1

0

as seen in val-doesnt-trigger-change-in-jquery

The solution was to add:

 $('#'e).val(i).trigger("change");

in my autocomplete.

bart2puck
  • 2,432
  • 3
  • 27
  • 53