1

I'm currently working on a web application. There, I created a Textbox (Works with jquery autocomplete) which shows up when the user clicks on a button. Then I want to load the needed source for autocomplete from my database. But I'm currently testing it with some random values. When I call this:

            $("#docNameTB").autocomplete({
            source: ["Apple", "Banana"]
        });

The console says: "Uncaught TypeError: $(...).autocomplete is not a function"

Here are my script sources:

    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.12.4.js"></script>
<script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

Here's my event code:

        function nextClicked() {
          $("#docNameTB").autocomplete({
              source: ["Apple", "Banana"]
          });
        }

And here's my Textbox:

               @Html.TextBox("docNameTB", "", new { @class = "form-control", @placeholder="Enter name here" })

Here's my button Press code:

            <a class="btn btn-default" id="nextButton" onclick="nextClicked()">Next &raquo;</a>

The solution of this question didn't work for me. I only use the google places script source too and this is not a problem (I have tested it already):

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=MY_KEY&libraries=places"></script>

Sry for my bad English and my formatting this is my first question. :) I hope somebody can help me! Thanks for your reply!

LRK
  • 123
  • 1
  • 8
  • Make sure you aren't loading jQuery.js again in page which would wipe out all the plugin methods contained in jQuery-UI – charlietfl Jun 24 '17 at 18:00
  • 1
    Possible duplicate of [.autocomplete is not a function Error](https://stackoverflow.com/questions/19591155/autocomplete-is-not-a-function-error) – mumair Jun 24 '17 at 18:03

4 Answers4

1

I searched for another 3 hours in the Internet and I read, read and read. And now I created my own solution, that worked for me. The trick was that I had to run autocomplete() on page load AND on button click.

Here's the Page load code:

    var docNameTB = $("#docNameTB");
    docNameTB.autocomplete({
        source: ["Banana", "Apple"]
    });

and here's the button click event code:

        function nextClicked() {
          docNameTB.autocomplete({
              source: ["Peach", "Ananas"]
          });
          // Other Code
        }

Maybe this is gonna help somebody too :)

LRK
  • 123
  • 1
  • 8
0

Try this HTML Part

<input type="text" class="form-control" onkeydown="nameSearch()" id="searchBox" placeholder="Search">

JS PART

function nameSearch()
{
$("#searchBox").autocomplete({
                source : ["Apple", "Banana"],
            });
}
0

Use this Sequences

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script src="yourJSFile"></script>
0

Use Jquery and Jquery UI CDn or Link at the head section

<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
Nazmul Haque
  • 720
  • 8
  • 13