Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    May 2005
    Posts
    78
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Issue with jQuery autocomplete script and dynamic input box

    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?

  • #2
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,956
    Thanks
    9
    Thanked 727 Times in 721 Posts
    Sounds like .live() attached to your autocomplete statement might do the trick.

  • #3
    New Coder
    Join Date
    May 2005
    Posts
    78
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by SB65 View Post
    Sounds like .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:
    Code:
    $(function(){$('.search').gcomplete();});
    I tried adding (document).ready, but it doesn't change anything. I also changed the
    Code:
    e.browser.mozilla?c.keydown(l):c.keydown(l);
    found in the autocomplete script to
    Code:
    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()?

  • #4
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,956
    Thanks
    9
    Thanked 727 Times in 721 Posts
    Assuming that your autocomplete fires on the focus event of your input field then you need to attach live() to that event:

    Code:
    $(function(){
    $('.search').live("focus",function(){
           $('.search').gcomplete();
           });
    });

  • #5
    New Coder
    Join Date
    May 2005
    Posts
    78
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •