1,105,225 Community Members

Autocomplete does not Autocomplete Correctly

Member Avatar
<M/>
Industrious Poster
4,472 posts since Apr 2012
Reputation Points: 106 [?]
Q&As Helped to Solve: 139 [?]
Skill Endorsements: 114 [?]
Featured
 
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)!

Member Avatar
pritaeas
mod_pritaeas
11,285 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,829 [?]
Skill Endorsements: 154 [?]
Moderator
Featured
Sponsor
 
0
 

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

Member Avatar
<M/>
Industrious Poster
4,472 posts since Apr 2012
Reputation Points: 106 [?]
Q&As Helped to Solve: 139 [?]
Skill Endorsements: 114 [?]
Featured
 
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>
Member Avatar
<M/>
Industrious Poster
4,472 posts since Apr 2012
Reputation Points: 106 [?]
Q&As Helped to Solve: 139 [?]
Skill Endorsements: 114 [?]
Featured
 
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)

Member Avatar
<M/>
Industrious Poster
4,472 posts since Apr 2012
Reputation Points: 106 [?]
Q&As Helped to Solve: 139 [?]
Skill Endorsements: 114 [?]
Featured
 
0
 

anyone?

Member Avatar
pritaeas
mod_pritaeas
11,285 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,829 [?]
Skill Endorsements: 154 [?]
Moderator
Featured
Sponsor
 
0
 

What autocomplete plugin are you using?

Member Avatar
<M/>
Industrious Poster
4,472 posts since Apr 2012
Reputation Points: 106 [?]
Q&As Helped to Solve: 139 [?]
Skill Endorsements: 114 [?]
Featured
 
0
 

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

Member Avatar
pritaeas
mod_pritaeas
11,285 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,829 [?]
Skill Endorsements: 154 [?]
Moderator
Featured
Sponsor
 
0
 
$("#CityAjax").autocomplete(

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

Member Avatar
<M/>
Industrious Poster
4,472 posts since Apr 2012
Reputation Points: 106 [?]
Q&As Helped to Solve: 139 [?]
Skill Endorsements: 114 [?]
Featured
 
0
 

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

Member Avatar
pritaeas
mod_pritaeas
11,285 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,829 [?]
Skill Endorsements: 154 [?]
Moderator
Featured
Sponsor
 
0
 

That would be creating a plugin with that name.

Member Avatar
<M/>
Industrious Poster
4,472 posts since Apr 2012
Reputation Points: 106 [?]
Q&As Helped to Solve: 139 [?]
Skill Endorsements: 114 [?]
Featured
 
0
 

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

Member Avatar
Dani
The Queen of DaniWeb
20,551 posts since Feb 2002
Reputation Points: 1,356 [?]
Q&As Helped to Solve: 927 [?]
Skill Endorsements: 203 [?]
Administrator
Featured
Sponsor
 
0
 

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

Member Avatar
<M/>
Industrious Poster
4,472 posts since Apr 2012
Reputation Points: 106 [?]
Q&As Helped to Solve: 139 [?]
Skill Endorsements: 114 [?]
Featured
 
0
 

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

Member Avatar
<M/>
Industrious Poster
4,472 posts since Apr 2012
Reputation Points: 106 [?]
Q&As Helped to Solve: 139 [?]
Skill Endorsements: 114 [?]
Featured
 
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.

Member Avatar
pritaeas
mod_pritaeas
11,285 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,829 [?]
Skill Endorsements: 154 [?]
Moderator
Featured
Sponsor
 
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.

Member Avatar
<M/>
Industrious Poster
4,472 posts since Apr 2012
Reputation Points: 106 [?]
Q&As Helped to Solve: 139 [?]
Skill Endorsements: 114 [?]
Featured
 
0
 

Do you have link to those samples on GitHub?

Charutayal
Newbie Poster
1 post since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 

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

http://jqueryui.com/autocomplete/

post me updated :)

Member Avatar
pritaeas
mod_pritaeas
11,285 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,829 [?]
Skill Endorsements: 154 [?]
Moderator
Featured
Sponsor
 
0
 

Sorry. Thought I'd added them:

https://github.com/pritaeas/hp-jquery

The first three links on my website here has usage demos too.

Member Avatar
<M/>
Industrious Poster
4,472 posts since Apr 2012
Reputation Points: 106 [?]
Q&As Helped to Solve: 139 [?]
Skill Endorsements: 114 [?]
Featured
 
0
 

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

Member Avatar
diafol
Where are my eyes?
12,940 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,845 [?]
Skill Endorsements: 90 [?]
Moderator
Featured
Sponsor
 
0
 

jQueryUI has a sample too: http://jqueryui.com/autocomplete/

LakTek seems to have a nice tute - but I can't comment on the quality too much:
http://www.laktek.com/2011/03/03/introducing-jquery-smart-autocomplete/

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