Hi, I am trying to implement a “auto fill/complete” /”Goggle suggest” function.

I found a great one at:
http://www.webreference.com/programming/javascript/ncz/column2/.

The code itself works beautifully. The problem, now, is this:

The script retracts the “list of suggestion’s” from this function:

function StateSuggestions() {
    this.states = [
        "Alabama", "Alaska", "Arizona", "Arkansas",
        "California", "Colorado", "Connecticut", (and so on) 
    ];
}

I want the “list of suggestion’s” to be retrieved from a database, handled by php, where the values (the array that holds the “list”) changes.

I tried using a XhttpRequest to get the values, and running them through the “eval()” function, without any luck.

I thought I give the problem a try at the forum to see if anyone knows what could be done. If else I have to build my own “auto-function” and I really do not want to do that, when the referred function otherwise works so well.

I would appreciate any input on this issue.

    Thanks for your reply AleXander S.

    I tried doing something like this:

    function states(name,query,url) {
    
      XHTTP=XHTTPinitiate();
      XHTTP.open("GET",url,true);
      XHTTP.send(null);
      var url=url+'?'+name+'='+query;
    
      XHTTP.onreadystatechange=function() {
        if (XHTTP.readyState==4 || XHTTP.readyState==200) { 
          this.states= eval(XHTTP.responseText) }
       }
    
    }

    I want to point out that this does work when passing variables (i.e. x = eval(XHTTP.responseText), and in the JS: alert(x)).

    The problem is that I can’t assign the dynamic values being processed in the PHP (the output from the PHP would be "['array1','array2','array3', etc.]").

    PS. Thanks for the suggestion of using script.aculo.us.library, however that script doesn’t "make my boat float” if you know what I mean… blink

      I solved the problem by creating my very own auto-fill/complete/suggest function, from scratch.

      I hope this helps anyone in the future that has a similar problem and looking for a solution. Good Luck.

        Write a Reply...