1

I am using SPAutocomplete for a type ahead input text box as shown below. This works great.

      $().SPServices.SPAutocomplete({
        sourceList: "mySourceList",
        sourceColumn: "mySourceColumn",
        columnName: "DestinationColumn",
        ignoreCase: true,
        numChars: 3,
        slideDownSpeed: 'fast'
    });

I want to write an onChange event on the input text box. Which works only when I type in the input text box and does not work with the autocomplete. I also tried KeyUp, KeyDown, KeyPress - with e=13 which did not work either.

    $('input[title="DestinationColumn"]').on('change', function () {
       // Logic here            
    });

Finally I am trying to attach the click event to the ul list items that dynamically generate during type ahead. Logic here. This is not working either.

   $('ul[id^="SPAutocomplete_DestinationColumn"] li').on('click', function () {
       // Logic here
    });

How can I write an onchange event with auto populate select on an input textbox? Any clues will be greatly appreciated. Thank you.

1 Answer 1

2

ok, I figured out issue, I attached the click event directly to the ul instead of ul li elements.

$('ul[id^="SPAutocomplete_DestinationColumn"]').on('click', function () {
   // at this point, the input text box holds the auto complete value that was clicked. this solved my issue. 
});
1
  • Thank you, this was driving me crazy. 4 hours thrown away. :) Commented Jan 30, 2018 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.