RenceAbi
RenceAbi

Reputation: 582

Autocomplete for dynamically created input using jQuery 3.2.1

I have found autocomplete for dynamically created inputs using jQuery 1.9.1, but I'm using jQuery 3.2.1 (am unable to change the version), kindly give me the solution for jQuery 3.2.1!

The example below is working fine in jQuery 1.9.1:

<script>
 var availableTags = {
     source: ["ActionScript", "AppleScript"],
     minLength: 2
 };
 $("#myProd0").autocomplete({
  source:availableTags
});
  </script>

<html>
<input type="text" name="myProd0" id="productname">
</html>

If I run the code above in jquery 3.2.1, it says autocomplete is not a function.

Check this: http://jsfiddle.net/6mtYe/ (changing to jQuery v3.1.2 won't work)

Upvotes: 0

Views: 815

Answers (2)

Dhruv Raval
Dhruv Raval

Reputation: 1583

use jquery ui

<script type="text/javascript" src="external/jquery/js/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="external/jquery-ui/js/jquery-ui-1.12.1.min.js"></script>
<script>
  var availableTags = {
     source: ["ActionScript", "AppleScript"],
     minLength: 2
  };
  $("#myProd0").autocomplete({
   source:availableTags
  });
</script>

check link

Upvotes: 0

varo90
varo90

Reputation: 56

I think JQuery UI is what you need, check this:

https://jqueryui.com/autocomplete/

If you click on "View source", you'll see an example with jquery version 1.12.4, but if you replace this line:

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>

for this line:

<script src="https://code.jquery.com/jquery-3.2.1.js"></script>

It still works.

Upvotes: 1

Related Questions