Hello I have some input who I use autocomplete but I have a add row but when I'm adding row I don't have the option of autocomplete. How I do autocomplete on my new row?
Here how I do my autocomplete :
//------------------AUTO COMPLETE NUMÉRO DE PROJET----------------------
$(document).ready(function(){
//-------AUTO COMPLETE DIMANCHE PROJET-----
$("#projdim").autocomplete({
source:'getautocomplete.php',
minLength:1
if enter is pressed
//------------------COMPLETE CLIENT DESC DIMANCHE----------------------
function handleEnter(e, obj, field){
if (e.keyCode == 13 || e.which == 13){
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
tempArrayInJS = JSON.parse(xmlhttp.responseText);
$("#clientdim").val( tempArrayInJS[0]['cliName']);
$("#prodescdim").val( tempArrayInJS[0]['proDescription']);
}
}
xmlhttp.open("GET","completeclient.php?q="+obj.value,true);
xmlhttp.send();
}
//Enter was pressed, handle it here
}
Here is my input original
<span id="numpro" >
<input onblur="autre();" onfocus="enter();" type="text" id="projdim" name="projdim"onkeypress="return handleEnter(event, this, 'task');"/>
</span>
Here how I add row
<?php if (!isset($_POST['Terminé'])) { ?>
<form action="insert.php" method="post" >
<b>Dimanche</b> </br><?php echo $date1 ?>
<p id="add_field"><a href="#"><span>add</span> </a></p>
</td>
My JS of adding row
<script type="text/javascript">
var counter = 0;
$(function(){
$('p#add_field').click(function(){
counter += 1;
$('#numpro').append(
'<input id="field_' + counter + '" name="dynfields[]' + '" type="text" />'
);
$('#proclient').append(
'<input id="field_' + counter + '" name="dynfieldstest[]' + '" type="text" /><br />'
);
});
});
</script>
Right now, you're only adding autocomplete to elements with id projdim
. You need to run the autocomplete function on every element you want it to effect. For example, change your append function to
$('p#add_field').click(function(){
counter += 1;
var $newRow = $('<input id="field_' + counter + '" name="dynfields[]' + '" type="text" />');
$('#numpro').append($newRow);
$newRow.autocomplete(autocompOpt);
...
autocompOpt
here is an object representing your autocomplete options. In the code you gave, something like
var autocompOpt = {
source:'getautocomplete.php',
minLength:1
}