carbide20 carbide20 - 3 months ago 68
jQuery Question

jQuery(...).autoComplete is not a function

I'm trying to get autoComplete() to work from jQuery-ui. I've created a fiddle to show my code:

https://jsfiddle.net/4s4dzwn1/

My JS:

jQuery(function(){

jQuery('#autocomplete').autoComplete({
source: ["ActionScript",
"Bootstrap",
"C",
"C++",
"Ecommerce",
"Jquery",
"Groovy",
"Java",
"JavaScript",
"Lua",
"Perl",
"Ruby",
"Scala",
"Swing",
"XHTML"]
});

});


My HTML:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>

<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>

<form>
<input id="autocomplete">
</form>


It's throwing an error that says autoComplete is not a function. My understanding is that autoComplete is a part of jQuery-ui (which is included), and that jQuery-ui should be included after jquery. Please correct me where I'm wrong.

Answer

Try This code

jQuery(function(){

    jQuery('#autocomplete').autocomplete({
        source: ["ActionScript",
            "Bootstrap",
            "C",
            "C++",
            "Ecommerce",
            "Jquery",
            "Groovy",
            "Java",
            "JavaScript",
            "Lua",
            "Perl",
            "Ruby",
            "Scala",
            "Swing",
            "XHTML"]
    });

});
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>

    <form>
        <input id="autocomplete">
    </form>