jQuery UI Autocomplete附加PHP和MySQL

i have a slightly small problem, i believe, i can't find the error...

What i have is a simple form, which is using autocomplete to find stuff in the database, this works for only the FIRST (default) input field.

What i want it to do is to "re-initialize" autocomplete on appended inputs, but it seems that i cant manage it, and i've tried google it all... (alot may say that :) ).

This is the JS-part.

$(function() {
        var i=0;
        var autocomp_opt={
                source: "functions.php",
                minLength: 3,

            }
                $(".itemname").on("keydown.autocomplete", function() { // this one works
                    $(this).autocomplete(autocomp_opt);
                });
                $(".itemname["+i+"]").on("keydown.autocomplete", function(){ // doesnt work
                    $(this).autocomplete(autocomp_opt);
                });

                $(".addfield").click(function(e){ //on add input button click
                    i++;
                     e.preventDefault();
                    $("#createList").append('<br /><input type="text" name="itemname['+i+']" class="itemname['+i+']" placeholder="Livsmedel" />');//add input box
                });
});

and here's the form :

            <form method="post" id="createList" action="create.php" class="pure-form" >
                <input type="text" name="itemname[0]" class="itemname" placeholder="Livsmedel" />
                <input type="text" name="amount" style="display:none" class="amount" placeholder="">
                <input type="text" name="unit" class="unit" />
                <button type="button" class="addfield" />+</button>
                <button type="submit" class="pure-button pure-button-primary" name="insert">Lägg in</button>
            </form>

The error should be quite simple, but i cant find it :(

Glad the link helped. I have worked a solution, too. It seems you're close but because i was not incrementing, your second function (the one not working) was failing.

I have it working here: http://jsfiddle.net/gd7qke4v/2/

What I did was adjust your basic autocomplete to this:

$(document).on("keydown", ".itemname", function () {
    //$(this).autocomplete(autocomp_opt);
    $(this).nextAll('input[name="unit"]').val('query result'); // here instead of val, use your autocomplete().   
});

which ties the autocomplete to the document, looks for .itemname to be active/keydown, then finds the next input with name of unit. Just replace the .val with your .autocomplete(autocomp_opt) and it should be set.