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)!

Recommended Answers

All 20 Replies

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

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>

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)

anyone?

What autocomplete plugin are you using?

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

$("#CityAjax").autocomplete(

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

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

That would be creating a plugin with that name.

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

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

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

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.

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.

Do you have link to those samples on GitHub?

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

@Diafol, i tried to follow the one on the jQueryUI site, i wasn't 100% successful.

But i will llook into the other link you provided.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.