简体   繁体   中英

Uncaught TypeError: Cannot read properties of undefined (reading 'length') . auto-suggestion in Jquery

simple code here am trying for auto suggestion

this is my autosuggestion code for written in .js file (inside (document).ready function)

$(function () {
        var list = [
            "One",
            "two",
            "Three",
            "Four",
        ];
        debugger;
        $("#text").autocomplete({
           
            minLength: 0,
            delay: 0,  
            placeholder: "Select Transporter...",
            source: list
        });

html code

<input type="text" id="text" value="text" />

error showing as :

Uncaught TypeError: Cannot read properties of undefined (reading 'length')

not able to see any moves.after entering somthing then when i come out of textbox . this above error comes in console please help me out . and share link where i can learn and implement about auto-sugestion

From https://jqueryui.com/autocomplete/ make sure you imported these two CDN

<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script src="https://code.jquery.com/ui/1.13.1/jquery-ui.js"></script>

final code would like this

<!doctype html>
<html>

<head>
    <title>Online jQuery Editor</title>
    <script src="https://code.jquery.com/jquery-3.6.0.js"></script>
    <script src="https://code.jquery.com/ui/1.13.1/jquery-ui.js"></script>
</head>

<body>
    <input type="text" id="text" value="text" />
</body>
<script>
    $(document).ready(function () {
        $(function () {
            var list = [
                "one",
                "two",
                "three",
                "four",
            ];
            debugger;
            $("#text").autocomplete({
                minLength: 0,
                delay: 0,
                placeholder: "Select Transporter...",
                source: list
            });
        })
    });
</script>

</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM