We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,055 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Autocomplete does not Autocomplete Correctly

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

6
Contributors
20
Replies
3 Weeks
Discussion Span
4 Months Ago
Last Updated
24
Views
<M/>
Senior Poster
3,611 posts since Apr 2012
Reputation Points: 64
Solved Threads: 78
Skill Endorsements: 90

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

pritaeas
Posting Prodigy
Moderator
9,287 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,458
Skill Endorsements: 86

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>
<M/>
Senior Poster
3,611 posts since Apr 2012
Reputation Points: 64
Solved Threads: 78
Skill Endorsements: 90

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)

<M/>
Senior Poster
3,611 posts since Apr 2012
Reputation Points: 64
Solved Threads: 78
Skill Endorsements: 90

anyone?

<M/>
Senior Poster
3,611 posts since Apr 2012
Reputation Points: 64
Solved Threads: 78
Skill Endorsements: 90

What autocomplete plugin are you using?

pritaeas
Posting Prodigy
Moderator
9,287 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,458
Skill Endorsements: 86

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

<M/>
Senior Poster
3,611 posts since Apr 2012
Reputation Points: 64
Solved Threads: 78
Skill Endorsements: 90
$("#CityAjax").autocomplete(

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

pritaeas
Posting Prodigy
Moderator
9,287 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,458
Skill Endorsements: 86

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

<M/>
Senior Poster
3,611 posts since Apr 2012
Reputation Points: 64
Solved Threads: 78
Skill Endorsements: 90

That would be creating a plugin with that name.

pritaeas
Posting Prodigy
Moderator
9,287 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,458
Skill Endorsements: 86

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

<M/>
Senior Poster
3,611 posts since Apr 2012
Reputation Points: 64
Solved Threads: 78
Skill Endorsements: 90

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

Dani
The Queen of DaniWeb
Administrator
21,343 posts since Feb 2002
Reputation Points: 1,555
Solved Threads: 367
Skill Endorsements: 122

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

<M/>
Senior Poster
3,611 posts since Apr 2012
Reputation Points: 64
Solved Threads: 78
Skill Endorsements: 90

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.

<M/>
Senior Poster
3,611 posts since Apr 2012
Reputation Points: 64
Solved Threads: 78
Skill Endorsements: 90

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.

pritaeas
Posting Prodigy
Moderator
9,287 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,458
Skill Endorsements: 86

Do you have link to those samples on GitHub?

<M/>
Senior Poster
3,611 posts since Apr 2012
Reputation Points: 64
Solved Threads: 78
Skill Endorsements: 90

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

http://jqueryui.com/autocomplete/

post me updated :)

Charutayal
Newbie Poster
1 post since Jan 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 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.

pritaeas
Posting Prodigy
Moderator
9,287 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,458
Skill Endorsements: 86

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

<M/>
Senior Poster
3,611 posts since Apr 2012
Reputation Points: 64
Solved Threads: 78
Skill Endorsements: 90

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/

diafol
Keep Smiling
Moderator
10,654 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,510
Skill Endorsements: 57

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.1147 seconds using 2.7MB