Have an account? Sign in
Login  Register  Facebook
help with - autocomplete structure
Hello all,

I'm lost here and I really need a kind guru to help me out and to have A LOT of patience.

Here is, more or less, the general workflow:
  • The user types something on a input element;
  • Onkeyup, it will grab values from our backend script, and choose one.
  • After choosing, onblur, we will grab that value and use it to query the database for some data,
  • With the data returned from the DB he will execute other commands on an external server.
  • Then it will grab that values and use them to fill some input elements that are there waiting to be filled in, once the user chooses is option from the autocomplete element.
  • With that data in place, the user can then change the values, and hit save for yet another "ajax adventure..."
So, here, we are on steps 1) and 2) only: (so I believe)

This is what I have been able to accomplish with the help of:
That I'm trying to understand and adapt.

//1) WHEN WILL verificaInput BE CALLED? 
$(document).ready(function verificaInput(inputString) {
    if (inputString.length == 0) {
        $('#sugestoes').hide();
    } else {
       
        $.post('modelAutocompleteTeste.php',
                  {nomeDominio: $('#nome-dominio').val()},
       
            function(dadosResposta){
               
                if(inputString.length > 3) {
                    $('#sugestoes').show();
                   
                     //2) WHAT SHOULD I PUT HERE?
                }
            },
       "json"
        );
    }
}
About 1): We must NOT use inline js calls ok. Where should we call/use the events like onkeyup and onblur etc... ? About 2):
function(dadosResposta){

This will contain the response from our server side script, if the input string
is greater then 3, it will show our suggestions... ok...
Now, inside this suggestion I will need to populate some elements (<li>) containing ALL the data returned in json format from our server side script (it's php - using json_encode) ?
If so, is this the proper place to loop over and create the li elements?


More then answers, I would like to ask for some advices... I'm lost and stuck.
Please advice, other then, "leave it a alone, and go fishing that you sure are better on that".
Started: September 21, 2011 Latest Activity: September 21, 2011 autocomplete js
1 Answer
I dont know if you have looked at it at all, but you may want to consider the jquery ui autocomplete plugin. It supports all of these things and is very well documented.

Posted: MacOS
In: September 21, 2011

Your Answer

xDo you want to answer this question? Please login or create an account to post your answer