1

I have an html file that references a couple of jquery files and has an array to pull the data for the input list, however; when I run the program I keep getting an error for the JS array saying "object expected". Any help would be appreciated.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title></title>
    <script type="text/javascript">  
      $(function() {
        var availableTags = [
            "ActionScript",
            "AppleScript",
            "Asp",
            "BASIC",
            "C",
            "C++",
            "Clojure",
            "COBOL",
            "ColdFusion",
            "Erlang",
            "Fortran",
            "Groovy",
            "Haskell",
            "Java",
            "JavaScript",
            "Lisp",
            "Perl",
            "PHP",
            "Python",
            "Ruby",
            "Scala",
            "Scheme"
        ];
        $("#tags").autocomplete({
            source: availableTags
        });
    });
    </script>

    <script src="jquery-1.7.1.js" type="text/javascript"></script>
    <script src="jquery.ui.widget.js" type="text/javascript"></script>

    <script src="jquery.ui.core.js" type="text/javascript"></script>

    <script src="jquery.ui.autocomplete.js" type="text/javascript"></script>

    <script src="jquery-ui.js" type="text/javascript"></script>
</head>
<body>
<div>
    <label for="tags">Tags: </label>
    <input id="tags" />
</div>
</body>

2
  • 3
    Try including jQuery (and related files) before your jQuery code. Commented Aug 1, 2012 at 16:54
  • 1
    @jbabey : .....and it's now posted as such ;) Commented Aug 1, 2012 at 16:58

2 Answers 2

1

Try including jQuery (and related files) before your jQuery code.

Sign up to request clarification or add additional context in comments.

Comments

0

In order for external scripts/libraries like jQuery to be useful, you need to include them before you actually use them. Simply move the content of the <script> tag to after all the external scripts, and it should work fine.

<script src="jquery-1.7.1.js" type="text/javascript"></script>
<script src="jquery.ui.widget.js" type="text/javascript"></script>
<script src="jquery.ui.core.js" type="text/javascript"></script>
<script src="jquery.ui.autocomplete.js" type="text/javascript"></script>
<script src="jquery-ui.js" type="text/javascript"></script>

<script type="text/javascript">  
  $(function() {
    var availableTags = [
        "ActionScript",
        "AppleScript",
        "Asp",
        "BASIC",
        "C",
        "C++",
        "Clojure",
        "COBOL",
        "ColdFusion",
        "Erlang",
        "Fortran",
        "Groovy",
        "Haskell",
        "Java",
        "JavaScript",
        "Lisp",
        "Perl",
        "PHP",
        "Python",
        "Ruby",
        "Scala",
        "Scheme"
    ];
    $("#tags").autocomplete({
        source: availableTags
    });
});
</script>

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.