Autocomplete jQuery on facebox

424 views Asked by At

I need to use autocomplete (In particular I try it with this plugin http://scottreeddesign.com/project/jsuggest) in my text input that it is in a facebox. But it didn't work beacause in the document ready there is my function:

                $(document).ready( function(){              

                        /** suggest new Quid **/
                        $('#idInput').jSuggest({
                             default_text: 'Inserisci il quid',
                             terms_url:      'data.php'+'%input%',
                             limit: 10
                        });   

                        $('#idLink').live('click', function(e) {  jQuery.facebox("<input type='text' id='idInput' />") });
                });

but initially the dom #idInput don't exist, it is show in the facebox only when I click a link.

Can you help me? Any suggestion?

p.s. the plugin jsuggest isn't required. It is the first that I've found.

2

There are 2 answers

1
Dalen On BEST ANSWER

the solution is bind the jSuggest plugin right on the click event:

 $('#idLink').live('click', function(e)
  {
    jQuery.facebox("<input type='text' id='idInput' />").jSuggest(
       {
          default_text: 'Inserisci il quid',
          terms_url:      'data.php'+'%input%',
          limit: 10
       });
  });

or maybe better:

 $('#idLink').live('click', function(e)
  {
    $("<input type='text' id='idInput' />").jSuggest(
       {
          default_text: 'Inserisci il quid',
          terms_url:      'data.php'+'%input%',
          limit: 10
       }).facebox();
  });

EDIT: the solutions above doesn't work then try this:

 $('#idLink').live('click', function(e)
  {
    $input = $("<input type='text' id='idInput' />");
    $input.jSuggest(
       {
          default_text: 'Inserisci il quid',
          terms_url:      'data.php'+'%input%',
          limit: 10
       });
    $input.facebox();
  });

Anyway I would suggest you to use jquery-ui's autocomplete.

0
Dany On

This is the solution that I try and it work!! Thanks to all!

I used this plugin: http://www.pengoworks.com/workshop/jquery/autocomplete.htm

               $(document).ready( function(){              

                        $('#idLink').live('click', function(e) {  

                            jQuery.facebox("<input type='text' id='idInput' />") });

                            /** suggest **/
                            $('#idInput').jSuggest({
                                default_text: 'default text here',
                                terms_url:      'data.php'+'%input%',
                                limit: 10
                            });   
                        });