background preloader

Autocomplete

Facebook Twitter

Accentué

AutoComplétion Code Postal/Ville avec jQuery. Using jQuery Autocomplete When Remote Source JSON Does Not Contain ‘Label’ or ‘Value’ Fields. If the jQuery autocomplete plugin uses a remote datasource, the autocomplete expects it to return json data with a ‘label’ and/or a ‘value’ field.

Using jQuery Autocomplete When Remote Source JSON Does Not Contain ‘Label’ or ‘Value’ Fields

If you return one, either ‘label’ or ‘value’, the autocomplete uses it for both the suggestion menu and the value of the input box. If you return both, it uses the ‘label’ for the suggestion menu and the ‘value’ for the value of the input box. What happens when the remote source returns neither a ‘label’ or ‘value’ and you cannot change the returned json of the remote source? How to parse JSON array in jQuery. jQuery UI Autocomplete with a remote database and PHP generating JSON data. I spent some time last night struggling with jQuery UI Autocomplete.

jQuery UI Autocomplete with a remote database and PHP generating JSON data

I was trying to use a remote data source, and was calling a php script to interrogate the database, no ajax. During the course of getting it to work properly, I discovered a couple of things that aren’t very clear in the documentation. The basic javascript, lifted straight from the jQuery UI demo is: Fine so far. There was one major thing that fooled me. Then this local data is queried each time a character is entered in the required field. $term = trim(strip_tags($_GET['term'])); $qstring = "SELECT description as value,id FROM test WHERE description LIKE '%". Hope this explanation is useful. Chez Syl » Développement web. Je vais vous expliquer comment faire facilement un système d’autocomplétion avec jQuery.

chez Syl » Développement web

Les données seront stockées en base de données. Tout d’abord, pour ne pas réinventer la roue, je vous propose d’utiliser un plugin jQuery d’autocomplétion (site web). Je le préfère à celui de jQuery UI qui lui est en revanche plus populaire. Nous allons donc utiliser celui du premier lien. Il faut tout d’abord télécharger le JS et le CSS. Mise en place On n’oublie pas de charger jQuery : Vous créez ensuite votre input le plus simple du monde : Et vous appelez le plugin dessus : On lui indique quel fichier appeler en Ajax, ce dernier va se charger de récupérer la valeur entrée par l’utilisateur (contenue dans $_GET['q']), de se connecter à la base de données, faire la requête SQL et d’afficher d’éventuels résultats.

Voici le PHP : Si vous avez des attentes particulières, regardez du côté des options du plugin. Démo. Highlight matched text using autocomplete. Thanks - for some reason I didn't see that post.

Highlight matched text using autocomplete

Going to work out if that will fix the issue. Frustrating thing is that I bought 2 jquery books (one dedicates 1 page to it and the other doesn't even mention autocomplete!) Currently, it is complaining about a "}" not being closed. My current code is: })); } }); }, minLength: 3) .data( "autocomplete" ). function __highlight(s, t) { var matcher = new RegExp("("+$.ui.autocomplete.escapeRegex(t)+")", "ig" ); return s.replace(matcher, "<strong>$1</strong>");}

jQuery UI Autocomplete Widget with PHP and MySQL. You might also be interested in the Using jQuery Autocomplete to Populate Another Autocomplete post.

jQuery UI Autocomplete Widget with PHP and MySQL

As a follow up to the jQuery UI Autocomplete Widget with ColdFusion post, I did one with PHP as the backend. The jQuery UI folks have released an autocomplete widget that is pretty slick. This example uses the json_encode function in PHP 5. If you have an earlier version of PHP, you will have to roll your own JSON string. This example will use US states and territories to populate the autocomplete. Of course, you will need the jQuery core file, the jQuery UI core file, and the jQuery UI style sheet of choice. jQuery: Autocomplete Tutorial.