0

I have created a jQuery autocomplete that works of an array generated by a PHP script:

var tags = [{"id":"77","label":"110826"},
            {"id":"76","label":"110667"},
            {"id":"74","label":"110808"}];

However the autocomplete box will not work - i am typing in values that are in the array but nothing is happening and I cannot figure out why.

Please see my fiddle here; http://jsfiddle.net/j4yB3/

Any help would be appreciated, thanks!

1
  • Works fine - you didn't include jQuery or jQuery UI in the fiddle Commented Sep 2, 2013 at 12:33

3 Answers 3

1

You hadn't closed your <label> tag (not that it really matters), but your Fiddle didn't have the jQueryUI and jQuery references.

Try THIS.

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

Comments

0

I have updated the fiddle code for the solution. Make sure you have added the jquery js and jquery ui js

Comments

0
<script>
  $(function() {
    var projects = [
      {
        value: "jquery",
        label: "jQuery",
        desc: "the write less, do more, JavaScript library",
        icon: "jquery_32x32.png"
      },
      {
        value: "jquery-ui",
        label: "jQuery UI",
        desc: "the official user interface library for jQuery",
        icon: "jqueryui_32x32.png"
      },
      {
        value: "sizzlejs",
        label: "Sizzle JS",
        desc: "a pure-JavaScript CSS selector engine",
        icon: "sizzlejs_32x32.png"
      }
    ];

    $( "#project" ).autocomplete({
      minLength: 0,
      source: projects,
      focus: function( event, ui ) {
        $( "#project" ).val( ui.item.label );
        return false;
      },
      select: function( event, ui ) {
        $( "#project" ).val( ui.item.label );
        $( "#project-id" ).val( ui.item.value );
        $( "#project-description" ).html( ui.item.desc );
        $( "#project-icon" ).attr( "src", "images/" + ui.item.icon );

        return false;
      }
    })
    .data( "ui-autocomplete" )._renderItem = function( ul, item ) {
      return $( "<li>" )
        .append( "<a>" + item.label + "<br>" + item.desc + "</a>" )
        .appendTo( ul );
    };
  });
  </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.