Loop in Jquery autocomplete

Asked

Viewed 171 times

2

I’m using this plugin - jquery autocomplete.

I have a select option and the plugin dynamically creates a input type="text" and hides the select. Everything works!

I would like to know how to make, every letter I type, do a search in the database to know if there is an equal word.

Actually, I just need to figure out how to go through the input text created with each typed letter.
Some guidance?

Here’s the project I took to use: http://jsfiddle.net/emirdeliz/swqwLfxu/

  • What programming language do you use? Php, Java, C#, Pyton?

  • Php and Jquery. Only in this case only Jquery is involved!

  • @Carlosrocha, do you want the Datasource of Autocomplete to be Remote? type, the autocomplete shows the first 10 results coming from the database containing the informed text.

  • No. Next. My Select has already been populated by the database. Normal. Now, Jquery has created a text box because a select does not accept typing. With each letter I type in the text box created by the plugin, it will autocomplete with the occurrences that exist in select, correct? What I wanted is that as the autocomplete finds matches as this autocomplete, a bank search is made. This search I know how to do, but this loop letter by letter I don’t know!

  • Gosh, no one knows that?

1 answer

2


  • Boy, that’s just what I wanted! I think I need to study some Jquery definitions. I even fired an Alert in the same position as $(" <input> "). on("keydown", Function() {Alert($(" <input> "). val());}). The keydown fired, but the Alert() only gave that the field is undefined! I guess I’ll have to do that too for onkeyup.*** Now just one more thing: How do I know if what has already been typed in the text field exists, or in the li or text field, there is a combination with some select (or text() option of some li?***

  • The keydown performs a function when a key is pressed, that is, before the letter is even inserted into the field. The keyup is already called when we release the key.

  • True, lack of attention on my part. Now just one more thing: How do I know if what has already been typed in the text field exists, or in the li or text field, there is a combination with some select (or text() option of some li?

  • I’m kind of curled up here, if I can’t later make another code, but the idea is inside the keyup, make a loop in the fields comparing the valuables. To make it easy, you can create an array at the root of the plugin, and save the value of all the fields, so just make a loop in this array

  • All right, I’ll try here too. But beforehand, thank you very much for the support!

  • I think I did, though, if the name of the plan is 1 MB FULL and I type 1 Mb full. That is, tiny, the array search does not find! How to solve this case insensitive problem?

  • in comparison, within the loop, the idea is to do so: if ( valordigitado.toLowerCase() == itemdoarray[ i ].toLowerCase() ), so it will transform the entire typed value into minuscule, and it will also transform the value to be checked into minuscule. That way, regardless of how you type and how the item is in the array, it will be let’s say 'compatible'

  • Yeah, I did it anyway. And I passed the normal value to php to do the search. of the plan price. Gave it right! again, I thank you very much.

  • Just 1 more thing. I have 2 selects on the page I use the plugin. then when events occur occur they occur for both selects. I did $(Document). on("click", "li", Function() { that$ are the li’s generated If I cliko in li’s of the select plans, it fires the event. If I cliko in the customers select, it also fires. Some resource?

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.