Autocomplete on a dynamically created input

Autocomplete on a dynamically created input

Hello..

 
So, what I'm trying to do is to get the autoComplete to work with any new appended <input> fields on my page.
The dynamically appended <input> fields are added to the page, when a button is pressed, by using insertRow/innerHTML within a table body.
 
Upon the creation of the new <input> field, it is given a name, an unique id, and an onFocus(function() {autoComplete('userRelative',(oID=+oID));} is set. eg.:
 
//Static <input> field - always visible on the page.
  1. <input type="text" name="userRelative[]" id="userRelative0" onFocus="autoComplete('userRelative','0');">
 
//dynamic <input> fields - created by using insertRow/innerHTML (a copy of above <input> field (with modifications)) within a table body.
  1. <input type="text" name="userRelative[]" id="userRelative1" onFocus="autoComplete('userRelative','1');">
  2. <input type="text" name="userRelative[]" id="userRelative2" onFocus="autoComplete('userRelative','2');">
 
... and so on...
 
I've managed to get the autoComplete function to work for both the 'static' and the 'dynamic' <input> fields, however: If the autoComplete function has been used on the first (static) <input> field, it won't work for any new created <input> fields.
 
If the dynamic <input> fields are created BEFORE typing anything in the first (static) <input> field, it works like a charm on both the dynamic and static fields.
But, this is only until the 'static' <input> field has been used - then if you choose to create a new field the autoComplete won't work (already created <input> fields are still working).
 
  1. function autoComplete(tableID, oID) {
  2.   $(function() {
  3.     function log( message ) {
  4.       $( "<div/>" ).text( message ).prependTo( "#log" );
  5.       $( "#log" ).attr( "scrollTop", 0 );
  6.     }
  7.     $( '#'+tableID+oID ).autocomplete({
  8.       source: "searchtest.php",
  9.       select: function( event, ui ) {
  10.         log( ui.item ?
  11.         "Selected: " + ui.item.value + " aka " + ui.item.id :
  12.         "Nothing selected, input was " + this.value );
  13.       }
  14.     });
  15.   });
  16. }
 
Any ideas how to solve this?
Please keep in mind that I'm a noob... But learning.
 
Thanks in advance.