View Full Version : Issue with jQuery autocomplete script and dynamic input box

09-16-2010, 08:27 AM
I've downloaded an autocomplete script (found here: http://blog.xlune.com/2010/02/jquerygcomplete.html) and it works perfectly. I have the script set to suggest autocompletions when a user types into the text input box with the id tag of "sf". However, this input box is often deleted by changing the innerHTML of the DIV element containing it, and replaced by another input box with the same id tag (sometimes a different id too, but it doesn't have to work with the other id's). When the input box is 'reset' (the parent's DIV innerHTML is changed), the script no longer works and no suggestions pop up when I type into the aforementioned input box.

How can I get the autocomplete script to work even after I've changed the parent DIV's innerHTML?

09-16-2010, 10:01 AM
Sounds like .live() (http://api.jquery.com/live/) attached to your autocomplete statement might do the trick.

09-27-2010, 03:32 AM
Sounds like .live() (http://api.jquery.com/live/) attached to your autocomplete statement might do the trick.

Thanks for your help, but I'm afraid I don't quite understand what you mean. I have no experience with jQuery, only Javascript. Here is the autocomplete function call on the web page:


I tried adding (document).ready, but it doesn't change anything. I also changed the
e.browser.mozilla?c.keydown(l):c.keydown(l); found in the autocomplete script to
e.browser.mozilla?c.live("keypress",l):c.live("keydown",l); and I also tried removing the unbind event found in the autocomplete script, all to no avail.

Where should I attach live()?

09-27-2010, 09:45 AM
Assuming that your autocomplete fires on the focus event of your input field then you need to attach live() to that event:


10-09-2010, 10:51 PM
I think it fires on the load event. In any case, I couldn't get it to work, but I managed to restructure the containing divs and change the input's attributes with javascript to achieve the same effect. Thanks for the help, this was quite a headache.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum