Issue with Dynamically added rows in HTML Table
<p>Im trying to add rows dyanmically to HTML table. Html table have a autocomplete textbox. When the page is loaded autocomplete is working fine and I capture INSERT key to insert a new row.
And its working fine too. Rows are added without any problem.</p>

<p>The problem i face is, autocomplete is ONLY WORKING in the first row and not in the row added dynamically, keydown event is also not working in the newly added row.</p>

<p>I think the problem is with id/name in the textbox. Your help is much appreciated.</p>

<p>My Script</p>

<pre><code>     &lt;script&gt;


$(function() {
   var availableTags = new Array();
  &lt;?php
     if($g_sql)
     {
         $i = 0;
         while ($result = mysql_fetch_array($g_sql))
         {
             ?&gt;
             availableTags[&lt;?php echo $i;?&gt;] = "&lt;?php echo $result['GroupName'];?&gt;";
             &lt;?php
             $i++;
         }
     }
 ?&gt; 
     $( "#txtmatg" ).autocomplete({
       source: availableTags
     });
 });
 $("#txtsn").keydown(function(e) {
    if(e.which == 45)
    {
        addRow('mattable');
    }
 }); 
&lt;/script&gt;
&lt;SCRIPT language="javascript"&gt;
function addRow(tableID)
{
    var table = document.getElementById(tableID);
    var rowCount = table.rows.length;
    var row = table.insertRow(rowCount);
    var colCount = table.rows[0].cells.length;
    for(var i=0; i&lt;colCount; i++) {
       var newcell = row.insertCell(i);
       newcell.innerHTML = table.rows[0].cells[i].innerHTML;
       switch(newcell.childNodes[0].type) {
       case "text":
           newcell.childNodes[0].value = "";
           break;
       }
     }
 }
     &lt;/SCRIPT&gt;
</code></pre>

<p>My HTML code is</p>

<pre><code>   &lt;div class="ui-widget"&gt;
      &lt;table id="mattable"&gt;
           &lt;tr&gt;
              &lt;td&gt;&lt;input type="text" name="txtmatg[]" id="txtmatg" class="input"&gt;&lt;/td&gt;
              &lt;td&gt;&lt;input type="text" name="txtmat[]" id="txtmat" class="input"&gt;&lt;/td&gt;
              &lt;td&gt;&lt;input type="text" name="txtsn[]" id="txtsn" class="input"&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
   &lt;/div&gt;
</code></pre>
