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.
- <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.
- <input type="text" name="userRelative[]" id="userRelative1" onFocus="autoComplete('userRelative','1');">
- <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).
- function autoComplete(tableID, oID) {
- $(function() {
- function log( message ) {
- $( "<div/>" ).text( message ).prependTo( "#log" );
- $( "#log" ).attr( "scrollTop", 0 );
- }
- $( '#'+tableID+oID ).autocomplete({
- source: "searchtest.php",
- select: function( event, ui ) {
- log( ui.item ?
- "Selected: " + ui.item.value + " aka " + ui.item.id :
- "Nothing selected, input was " + this.value );
- }
- });
- });
- }
Any ideas how to solve this?
Please keep in mind that I'm a noob... But learning.
Thanks in advance.