Question

When I use a simple local array I have no problems. I have no problems populating that array from MySQL, too. But when I try to load an array of object, even a local array, it doesn't work. What am I missing?

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>autocomplete demo</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
  <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>
</head>
<body>
    <label for="autocomplete">Select a programming language: </label>
    <input id="autocomplete">
    <script>
    $( "#autocomplete" ).autocomplete({
        source: [ { label:"c++", value=1 }, { label: "java", value=2 }, { label: "javascript", value=3 } ]
    });
    </script>
</body>
</html>
Was it helpful?

Solution

Because your syntax for defining property values for an object literal is incorrect:

[ 
    { 
        label:"c++", 
        value: 1 /* Be sure to use ":" and not "=" here */
    } 
]

Use : instead of =.

A tool like JSLint or JSHint will help you find simple errors like this.

Example: http://jsfiddle.net/92Qjw/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top