1.11M Members

Autocomplete does not Autocomplete Correctly

 
0
 

I wrote an autocomplete input (i don't think that is the best thing to call it) in jquery. What it does is auto completes your text. It does that but it autocompletes by re-displaying the whole word/s rather than displaying what is left.

I think I am un-clear, I may need to repeat.

*I will provide my code if needed (jQuery)!

 
0
 

Without code, it'll be difficult to spot the problem. If you can reproduce the problem on jsfiddle even better.

 
0
 

Sorry for my late response... I forgot about this thread... (sadly)

Here is my php

$q = strtolower($_GET["q"]);
if (!$q) return;
$items = array(
"        Los Angeles"=>"1",
"        Dubai"=>"2",
"        New York"=>"3",
"        Kabul"=>"4"
);

foreach ($items as $key=>$value) {
    if (strpos(strtolower($key), $q) !== false) {
        echo "$key|$value\n";
    }
}

?>

jquery

<script type="text/javascript">
  function findValue(li) {
    if( li == null ) return alert("No match!");
    if( !!li.extra ) var sValue = li.extra[0];
    else var sValue = li.selectValue;
  }
  function selectItem(li) {
        findValue(li);
  }
  function formatItem(row) {
        return row[0] + " (id: " + row[1] + ")";
  }
  function lookupAjax(){
    var oSuggest = $("#CityAjax")[0].autocompleter;
    oSuggest.findValue();
    return false;
  }
  function lookupLocal(){
        var oSuggest = $("#CityLocal")[0].autocompleter;
        oSuggest.findValue();
        return false;
  }
    $("#CityAjax").autocomplete(
      "autocomplete.php",
      {
            delay:10,
            minChars:2,
            matchSubset:1,
            matchContains:1,
            cacheLength:10,
            onItemSelect:selectItem,
            onFindValue:findValue,
            formatItem:formatItem,
            autoFill:true
        }
    );

</script>
 
0
 

I forgot to mention but what does "OP Kudos" mean? I see it on the link if you click this thread...

(please disregard me posting twice in the same thread)

 
0
 

anyone?

 
0
 

What autocomplete plugin are you using?

 
0
 

i am not using a plugin, i am trying to do this from scratch.

 
0
 
$("#CityAjax").autocomplete(

This call, where is it defined? I don't see code for autocomplete.

 
0
 

I think that could be the problem, how would i fix that?

 
0
 

That would be creating a plugin with that name.

 
0
 

How would you set up the plugin, I'm not sure how to do that?

 
0
 

OP Kudos means that the thread's original poster (YOU!) has lots of kudos with our community.

 
0
 

Oh okay, but are you able to assist me with the original question though?

 
0
 

I have another question about OP Kudos... you said it means (I) have lots of kudos with our community but why is that all my threads don't have OP Kudos on it?... Sorry if you count this as a bump... I couldn't edit my post and add on to it.

 
0
 

How would you set up the plugin, I'm not sure how to do that?

You can find lots of samples on the subject. See the jQuery website or use a search engine.

Additionally, I have three older plugins on GitHub which you can check out.

 
0
 

Do you have link to those samples on GitHub?

 
0
 

Please go though the link and check the solution with Source code.

http://jqueryui.com/autocomplete/

post me updated :)

 
0
 

okay thanks, I am going to check on those and update my progress afterwards

Isn't it about time forums rewarded their contributors?

Earn rewards points for helping others. Gain kudos. Cash out. Get better answers yourself.

It's as simple as contributing editorial or replying to discussions labeled or OP Kudos

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article