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 :(