AutoCompleter Tutorial
As always, links to a demo and ZIP at the bottom, Enjoy!
I thought i would write this tutorial because most of the auto completer applications i have seen just dump the code into a zip and tell you how to use it rather than how and why it works, knowing about this enables you to customise it a lot more (this has been demonstrated with the other apps i have written here)!

And so we begin:
JavaScript
function lookup(inputString) {
if(inputString.length == 0) {
// Hide the suggestion box.
$(‘#suggestions’).hide();
} else {
$.post("rpc.php", {queryString: ""+inputString+""}, function(data){
if(data.length >0) {
$(‘#suggestions’).show();
$(‘#autoSuggestionsList’).html(data);
}
});
}
} // lookup
function fill(thisValue) {
$(‘#inputString’).val(thisValue);
$(‘#suggestions’).hide();
}
</script>
JS Explaniation
Ok, the above code it the guts to the script, this allows us to hook into the rpc.php file which carries out all the processing.
The Lookup function takes the word from the input box and POSTS it to the rpc.php page using the jQuery Ajax POST call.
IF the inputString is ‘0′ (Zero), it hides the suggestion box, naturally you would not want this showing if there is nothing in the text box. to search for.
ELSE we take the ‘inputString’ and post it to the rpc.php page, the jQuery $.post() function is used as follows…
The ‘callback’ part allows to hook in a function, this is where the real magic if thats what you can call it happens.
IF the ‘data’ returned length is more than zero (ie: there is actually something to show), show the suggestionBox and replace the HTML inside with the returned data.
SIMPLE!
Now for the PHP Backend (RPC.php)
As always my PHP Backend page is called rpc.php (Remote Procedure Call) not that it actually does that, but hey-ho.
$query = $db->query("SELECT value FROM countries WHERE value LIKE ‘$queryString%’ LIMIT 10");
if($query) {
// While there are results loop through them – fetching an Object (i like PHP5 btw!).
while ($result = $query ->fetch_object()) {
// Format the results, im using <li> for the list, you can change it.
// The onClick function fills the textbox with the result.
echo ‘<li onclick="fill(‘‘.$result->value.’‘);">’.$result->value.‘</li>’;
}
} else {
echo ‘ERROR: There was a problem with the query.’;
}
} else {
// Dont do anything.
} // There is a queryString.
} else {
echo ‘There should be no direct access to this script!’;
}
}
?>
PHP Explaination
Im not going to go into much detail here because there are loads of comments in the code above.
Basically, it takes the ‘QueryString’ and does a query with a wildcard at the en.
This means that in this case of the code each key-press generates a new query, this is MySQL intensive if its always being done, but short of making it exceedingly complex it is fine for small scale applications.
The PHP code is the part you have to change to work in your system, and all the it is updating the ‘$query’ to your database, you should be able to see where you put the table column name in etc…
CSS Styling – im using CSS3, YEA BABY! much easier although limits the functionality to Firefox and Safari.
.suggestionsBox {
position: relative;
left: 30px;
margin: 10px 0px 0px 0px;
width: 200px;
background-color: #212427;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
border: 2px solid #000;
color: #fff;
}
.suggestionList {
margin: 0px;
padding: 0px;
}
.suggestionList li {
margin: 0px 0px 3px 0px;
padding: 3px;
cursor: pointer;
}
.suggestionList li:hover {
background-color: #659CD8;
}
</style>
The CSS is pretty standard, nothing out of the ordinary.
Main HTML
<div>
Type your county (for the demo):
<input size="30" id="inputString" onkeyup="lookup(this.value);" type="text" />
</div> <div class="suggestionsBox" id="suggestions" style="display: none;">
<img src="upArrow.png" style="position: relative; top: -12px; left: 30px" alt="upArrow" />
<div class="suggestionList" id="autoSuggestionsList">
</div>
</div>
</div>
That is the main bit of HTML, really all you need to run this is an input text box with the ‘onkeyup’ function set to lookup(this.value); Also, i recommend NOT changing the ID of the input box, unless you change it in the Javascript section
Screenshots
I suppose you want to see some more screen shots…. OK.

And another one!

And now for the links… this is probably what you are all looking for!
Demo: Auto Complete Demo
Source ZIP: AutoComplete Source ZIP
If you have any problems, just post them up here (as comments) and i am sure i can help you fix it
Thanks for the continued support,
Jamie.

























































































































































950 Responses for "AutoCompleter Tutorial – jQuery(Ajax)/PHP/MySQL"
You’ve left yourself wide open for SQL injection here… Take a look at the mysqli_real_escape_string() function to protect yourself.
Hi Mike,
Good spot, i wasn’t writing it with security in mind
I have the demo version running with a user who can only ‘SELECT’ from the database.
This has now also been updated in the Source ZIP
For those who are interested, this is what was changed in the code:
Replace
$queryString = $_POST['queryString'];With
$queryString = $db->real_escape_string($_POST['queryString']);
Cheers for your help Mike!
Jamie.
Hi Jamie,
I’ve got this script working, but the highlighting of the list items does not work unless I have this added to my html form.
If i add that line of code it works, but it stuffs up all the sizes of my html controls.
I don’t really understand how to use DTD and really don’t want it.
Is there a way of getting the list items highlighed without using the DTD?
Thanks
Tristan
When I submitted it removed the line of code. So above doesn’t make much sense!
The line I’m talking about is the very top line of the html page which references the DTD, if I don’t have that the highlighting doesn’t show. If I add it, it changes all the sizes of my listboxes and effects the look of some of my controls.
I figured out my problem. I hadn’t correctly specified the width=220px:, instead in my tags I had width=220 and when I added the DTD it caused problems with my page.
But I have another question. How do you get the suggestionbox to lose focus if the user doesn’t select an item but clicks elsewhere.
Hi Tristan,
Sorry you had to figure that all out one your own last night, i could not look at another computer screen when i got home last night…
With regards to the DTD i never really pay much attention to them, the reason its in the demo is because i used Microsoft Expression Web to create it as a test.
Now… to make it loose focus:
The textbox already looses focus, but we have to hook a new property to it.
Add this into the tag:
onblur="$('#suggestions').hide();"Let me know if that solves your problem.
Jamie.
Hmmm,
Adding the above code breaks the fill() function because it has in-effect lost focus and is hiding.
Let me have a play around.
Jamie.
Ok, i got it.
We need to replace the fill() function to add a timeout… do the following.
Replace the fill() function with
function fill(thisValue) {
$('#inputString').val(thisValue);
setTimeout("$('#suggestions').hide();", 200);
}
Add this onBlur to the ‘input’ tag
onblur="fill();"That should be it
This has also been updated in the ZIP!
Jamie.
This looks like a really good tutoral, very well explained – its a shame others dont explain the code they provide in a tutorial instead of just handing it out!!!
the script it failed. send to me script original of autoComplete.
Hi Edwin,
Can you be a bit more specific about how its not working, or provide a link to the script on your server.
Jamie.
Minor javascript error on the demo page:
- urchinTracker is not defined -
urchinTracker();
FF on Mac and maybe others don’t allow keyboard to select values. Some of the others like YUI and Scriptaculous allow for this. Are you working on something similar?
Hi Joel,
This will be implemented in v1.2
Jamie.
Hi Rrrrrrrrr,
Thanks for picking that one up… im assuming you have firebug aswell
Fixed!
Jamie.
Hi,
Its great.Thanks
[...] Mcconnell has taken the age old classic Ajax autocompleter, and has created a simple tutorial using jQuery and PHP. Jamie takes time to explain the “why” as much as the [...]
[...] Nodstrum » Blog Archive » AutoCompleter Tutorial – jQuery(Ajax)/PHP/MySQL (tags: jquery ajax autocomplete php tutorial javascript) [...]
Very nice tutorial. To be really picky, you should separate content and behaviour by adding event handlers with $(“#id”).bind(“click”, …
Dave
Hi Dave,
Thanks, i’ll look into doing that in my next tutorial!
Thanks for the pointer
Jamie.
Hi,
nice tutorial.
Here some ideas:
- the left/right/up/down cursor-keys shouldn’t send a request. SHIFT+Key and ALT-GR+Key shouldn’t send 2 requests.
- real supporting for the space char: “a bla foo” gives at this time the same result list like “a”
Best regards.
[...] Mcconnell has taken the age old classic Ajax autocompleter, and has created a simple tutorial using jQuery and PHP. Jamie takes time to explain the “why” as much as the [...]
[...] Nodstrum » Blog Archive » AutoCompleter Tutorial – jQuery(Ajax)/PHP/MySQL (tags: ajax form jquery php tutorial autocomplete guide webdesign webdev web development) [...]
[...] Nodstrum » Blog Archive » AutoCompleter Tutorial – jQuery(Ajax)/PHP/MySQL (tags: ajax jquery php autocomplete tutorial javascript form development *) [...]
Hey nice post can u please tell me how to use using Rails.
Hi Arun,
I am not using Rails in this tutorial, it is pure PHP
Jamie.
Nice script. I’m from Brazil and here we have the words with “´`ç” and the word example “Senhor dos Anéis” at this script appear “Senhor dos An?” how i correct this?
For the Russian language with the win-1251 codepage (not UTF8) must convert data between codepage. Both$queryString and $result->value.
$queryString = iconv(‘UTF-8′, ‘CP1251′,$queryString);
…
$strUTF = iconv(‘CP1251′, ‘UTF-8′,$result->value);
echo ”.$strUTF.”;
Very nice script, thanks. But still I have some problems with it.
How to make the suggestionsBox to overlayother web content that is present before suggestionbox is displayed? It normaly does cover rest of the page under it in IE7 but not in firefox. I tried z-index without any success.
I also tried to change postition property to absolute which solves my problem, but then position of suggestbox is changing depending on the browser window size.
Does anyone know what how to solve this issue?
Thanks Michal
[...] Nodstrum » Blog Archive » AutoCompleter Tutorial – jQuery(Ajax)/PHP/MySQL (tags: ajax jquery php tutorial) [...]
Nice tutorial! Thanks for taking the time
Just two quick things:
1. “As always my PHP Backend page is called rpc.php (Remote Procedure Call) not that it actually does that, but hey-ho.”
Can I suggest not naming this file incorrectly?
It’s not an RPC!
2. Also. Please don’t use CSS3 yet.
not working
very cool example.
[...] Nodstrun.com han publicado un sencillo tutorial en el que nos explican cómo implementar de forma elegante la funcionalidad de [...]
Can you please make a php4.3 version? I’ve tried it for a couple of hours now, without the big succes
[...] AutoCompleter Tutorial – jQuery(Ajax)/PHP/MySQL (tags: webdev jquery ajax javascript) [...]
not working well when i type space in first position……
I have only access to PHP4 so I get some errors.
Can the code be written for PHP4? If so what needs to be changed?
Love this.
Best
B
Hie. I have been trying this code but without success. I am new to PHP Web development and I guess there is something I am not doing right. I merely copied the files in my dreamweaver environment. Changed the database connection and query to suit my environment. However, every time I load the page and type something, I get an erreor to the effect referencing the line to do with Color style. Please advise. Are there classes to load before using your code snippets?
[...] Script : http://nodstrum.com/2007/09/19/autocompleter/ [...]
[...] publicado en Nodstrum un tutorial sobre como hacer un autocompleter con tecnología JQuery os recomiendo que lo leais, [...]
[...] ??? ????? Nodstrum ? Blog Archive ? AutoCompleter Tutorial – jQuery(Ajax)/PHP/MySQL __________________ |^^^^^^^^^ .|| | samry. ___ ||’""|""___, | ___________ l [...]
Here is a code compatible with PHP4 . Replace rpc.php with this content .
0) {
// Run the query: We use LIKE ‘$queryString%’
// The percentage sign is a wild-card, in my example of countries it works like this…
// $queryString = ‘Uni’;
// Returned data = ‘United States, United Kindom’;
// YOU NEED TO ALTER THE QUERY TO MATCH YOUR DATABASE.
// eg: SELECT yourColumnName FROM yourTable WHERE yourColumnName LIKE ‘$queryString%’ LIMIT 10
$result = mysql_query(“SELECT `value` FROM `countries` WHERE `value` LIKE ‘$queryString%’ LIMIT 10″);
//if($result) {
//fetch rows from result set.
while ($row = mysql_fetch_assoc($result)) {
// Format the results, im using for the list, you can change it.
// The onClick function fills the textbox with the result.
// YOU MUST CHANGE: $result->value to $result->your_colum
echo ”.$row['value'].”;
}
//} else {
//echo ‘ERROR: There was a problem with the query.’;
//}
} else {
// Dont do anything.
} // There is a queryString.
} else {
echo ‘There should be no direct access to this script!’;
}
?>
Nice, though I’d still go for writing Ajax in a RAD Framework like ours…
A version of rpc can be better for dynamic search.
include(“classe_database.php”);
$database = new Database();
if(isset($_POST['queryString'])) {
$queryString = $_POST['queryString'];
$tabella = $_POST['tabella'];
$campo = $_POST['campo'];
if(strlen($queryString) >0) {
$sql = “SELECT $campo FROM $tabella WHERE $campo LIKE ‘$queryString%’ LIMIT 10″;
$database->Query($sql);
$result = $database->result;
$num = mysql_num_rows($result);
if($result) {
for($i = 0; $i ‘.mysql_result($result,$i,$campo).”;
}
} else {
echo ‘ERRORE: Problema nella query.’;
}
} else {
}
} else {
echo ”;
}
and this is the javascript code must be set on header
function lookup(inputString) {
if(inputString.length == 0) {
// Hide the suggestion box.
$(‘#suggestions’).hide();
} else {
$.post(\”rpc.php\”, {queryString: \”\”+inputString+\”\”,tabella:\”prova\”, campo:\”\”+document.modulo_prova.cerca.value+\”\”}, function(data){
if(data.length >0) {
$(‘#suggestions’).show();
$(‘#autoSuggestionsList’).html(data);
}
});
}
} // lookup
function fill(thisValue) {
$(‘#inputString’).val(thisValue);
setTimeout(\”$(‘#suggestions’).hide();\”, 200);
}
and the form can be search in different column
echo “”;
$select2.= “titolo”;
$select2.= “descrizione”;
echo “”;
echo $select2;
echo “”;
echo ” Cerca: “;
echo ”
“;
Can be a little mod
Oh sorry, the post doesnt good cuz block html tags. Email me so i can give you all code.
[...] Collis wrote an interesting post today!.Here’s a quick excerptI thought i would write this tutorial because most of the auto completer applications i have seen just dump the code into a zip and tell you how to use it rather than how and why it works, knowing about this enables you to customise it … [...]
Nice tutorial, how do i make that the swedish letters å,ä and ö can be displayed in the suggest box?
Awesome tutorial. finally somone who explains the code. I was wondering is it possible to make some additions so text is added to the text box as user is typing. so he can just press enter? also if its possible to make up and down arrow keys work ..rather than mouse click (on the auto complete list show)
Thanks a lot again!
I have some problems with the code. Don’t working with some turkish characters like ‘?’. Saying ‘ERROR: There was a problem with the query.’ Another problem is how can i send suggested data to my search page? I did use action=”xxx.php” method=”POST” in form field but not working. Please advise me. Thanks.
Ok here is the code for turkish characters problems solving.
———-
$db = new mysqli(‘adress’,'user’,'pass’,'database’);
$db->query(“SET NAMES ‘latin5′”);
$db->query(“SET CHARACTER SET latin5″);
$db->query(“SET COLLATION_CONNECTION = ‘latin5_turkish_ci’”);
.
.
.
if(isset($_POST['queryString'])) {
$queryString = $db->real_escape_string($_POST['queryString']);
$queryString = iconv(‘UTF-8′,’latin5′,$queryString);
.
.
.
$strUTF = iconv(‘latin5′,’UTF-8′,$result->your_column);
echo(”.$strUTF.”);
————-
I have some problems with the code.
Don’t working with thai characters.
Hi, for some reason, this doesn’t work for me. I downloaded but when I try to type something in the input box, it shows me the entire PHP file starting from “real_escape_string($_POST['queryString']” i.e. the PHP file doesn’t appear to be processing. Any idea what could be causing this? Thanks.
hello, do you have a clean code (full code) of rpc to work with php4 , thanks
my problem is i have juste the big square black and nothing write in, the results search is ok but nothing appear in this box … thanks if you have a solution
[...] AutoCompleter – using jQuery(Ajax), PHP and MySQL, Tutorial and demo included. http://nodstrum.com/2007/09/19/autocompleter/ [...]
Here’s the COMPLETE WORKING CODE for PHP4, for those who are still running PHP4 instead of migrating to PHP5. I’ve spend 2 hours making sure everything was alright. Make sure to check for the ” and ‘ didn’t get replaced for erroneous stuff.
Author may feel like adding the php4 file to the zip too..which would be nice for clueless people
0) {
// Run the query: We use LIKE ‘$queryString%’
// The percentage sign is a wild-card, in my example of countries it works like this…
// $queryString = ‘Uni’;
// Returned data = ‘United States, United Kindom’;
// YOU NEED TO ALTER THE QUERY TO MATCH YOUR DATABASE.
// eg: SELECT yourColumnName FROM yourTable WHERE yourColumnName LIKE ‘$queryString%’ LIMIT 10
$result = mysql_query(“SELECT name FROM countries WHERE value LIKE ‘$queryString%’ LIMIT 10″);
if($result) {
//fetch rows from result set.
while ($row = mysql_fetch_assoc($result) ) {
echo ‘ ‘.$row['value'].”;
}
} else{
//echo ‘ERROR: There was a problem with the query.’;
}
} else {
// Dont do anything.
} // There is a queryString.
} else {
echo ‘There should be no direct access to this script!’;
}
}
?>
Sorry for double posting, but for those who want the file in PHP4, just head to http://www.almateria.net/rpc_php4.php
That’s all. Hopefully that will help someone!
Hi all,
Would it be possible for the suggestion div to overlay the rest of the form that’d be below the input box with autocompleter?
If the input is in the middle of a form whatever is below it is moved and depending on the rest of the page: messed up…
Thanks for this great tutorial and your help…
Hello everybody:
I have a problem. When put into operation on autocompletador, the results do not appear. Box appears in black, even makes the filter list, but it appears in black. Even when making a selection, input is blank. This is the code that I used.
real_escape_string($_POST['queryString']);
// Is the string length greater than 0?
if(strlen($queryString) >0) {
// Run the query: We use LIKE ‘$queryString%’
// The percentage sign is a wild-card, in my example of countries it works like this…
// $queryString = ‘Uni’;
// Returned data = ‘United States, United Kindom’;
// YOU NEED TO ALTER THE QUERY TO MATCH YOUR DATABASE.
// eg: SELECT yourColumnName FROM yourTable WHERE yourColumnName LIKE ‘$queryString%’ LIMIT 10
$query = $db->query(“SELECT Nombre_alimento FROM tb_alimentos WHERE Nombre_alimento LIKE ‘$queryString%’ LIMIT 10″);
if($query) {
// While there are results loop through them – fetching an Object (i like PHP5 btw!).
while ($result = $query ->fetch_object()) {
// Format the results, im using for the list, you can change it.
// The onClick function fills the textbox with the result.
// YOU MUST CHANGE: $result->value to $result->your_colum
echo ‘value.’\');”>’.$result->value.”;
}
} else {
echo ‘ERROR: There was a problem with the query.’;
}
} else {
// Dont do anything.
} // There is a queryString.
} else {
echo ‘There should be no direct access to this script!’;
}
}
?>
Hello everybody:
I have a problem. When put into operation on autocompletador, the results do not appear. Box appears in black, even makes the filter list, but it appears in black. Even when making a selection, input is blank. This is the code that I used.
real_escape_string($_POST['queryString']);
if(strlen($queryString) >0) {
$query = $db->query(“SELECT Nombre_alimento FROM tb_alimentos WHERE Nombre_alimento LIKE ‘$queryString%’ LIMIT 10″);
if($query) {
while ($result = $query ->fetch_object()) {
echo ‘value.’\');”>’.$result->value.”;
}
} else {
echo ‘ERROR: There was a problem with the query.’;
}
} else {
} else {
echo ‘There should be no direct access to this script!’;
}
}
?>
<>
in the while replace the “value” word for the name of yourColumnName. in your case raplace “value” for “Nombre_alimento”.
Yo tenia el mismo error pero ya lo acabo de solucionar.
Nice work for this tutorial.
I am just having a little trouble implementing more text boxes into this script. What i am after is when the auto complete box has done its stuff and the right data has filled it, it selects the rest of my data from the same MYSQL row and puts it into more text boxes.
This is a brilliant script, keep up the good work
Thank You.
[...] Autocomplete – jQuery ajax [...]
Hai!
this is best script for developers.
Thanks.
How do you use this together with MooTools? The script seems to break when used together with MooTools
How do we use this in conjuction with MooTools? It seems to break when I try to include MooTools.
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
someone can zip and post the total files for php4 please, thanks again
hi again, i have found one day a zip file autocompleter but not this one post with (class.php , config.php, fonctions.php ,jquery.js , rpc.php) do you know where is the link to download ? thanks
Hi there,
First of all this is a great script.
Guys like me need guys like u
I spend about a whole night to get the up and down key functional and the enter key for selecting it and it stil doenst work for me.
Is there any way u can help me with this ?
With regards,
Jelle
Hi,
This is a great script. Great for newbie developers like me.
I was wondering :
1)is there a way to use the up and down arrows to scroll through the list
i’ve tried but can seem to get the logic going.
2)how can a add functionality to continue with the listing again even after selecting.
Just like in Yahoo! Mail or Gmail email address fields.
Thanks
Please I need the code for PHP4, the page posted by Nilopc not found. Thanks
[...] AutoCompleter Tutorial – jQuery(Ajax)/PHP/MySQL, show you how and why it works, knowing about this enables you to [...]
it is very useful. thank you.
[...] Autocomplete – jQuery ajax [...]
[...] AutoCompleter Tutorial [...]
Could you display a “no result!” when the suggestion doesn’t exist?
sorprendido, me gustaria aprobechar esto saludos!!
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
[...] Autocomplete by AjaxDaddy jQuery Autocomplete Plugin with HTML formatting jQuery Autocompleter AutoCompleter (Tutorial with PHP&MySQL) quick Search jQuery [...]
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
Hello,
Any idea, how to insert selected value into mysql db??
I keep getting
ERROR: There was a problem with the query.
even though I ma using this code.
$query = $db->query(“SELECT value FROM countries WHERE value LIKE ‘$queryString%’ LIMIT 10″);
Any ideas why??
Thanks
John: That query seems perfectly fine in its syntax, however, I would speculate that you have not imported the SQL file resulting in the query not being able to find a table or a column in a table, and thus returning you an over-friendly error.
[...] AutoCompleter Tutorial – jQuery(Ajax)/PHP/MySQL Lanuch Demo/site [...]
[...] AutoCompleter Tutorial – jQuery(Ajax)/PHP/MySQL, show you how and why it works, knowing about this enables you to [...]
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
[...] AutoCompleter (Tutorial with PHP&MySQL). [...]
[...] Autocomplete – jQuery ajax [...]
[...] Autocomplete by AjaxDaddy.jQuery Autocomplete Plugin with HTML formatting.jQuery Autocompleter.AutoCompleter (Tutorial with PHP&MySQL).quick Search jQuery Plugin.?????(Inline Edit & Editors)jTagEditor.WYMeditor.jQuery [...]
Hi, I have got this working good in all tested browsers but in Opera and Firefox there’s a small nag in the suggestionbox first row. The characters that appear on the first row are “”.
This row is not selectable so it’s not db output. I roled that out by not doint any db at all. It’s not the css, ruled that out by having none at all. Still these characters show. In IE it looks great. Seen this? any ideas?
cheers, //J
Hi Jan,
these characters seem to be added when Windows gets hold of the file when editting.
To fix this have a look at line 1 in all the files associated with my auto-completer. In one of them will be these characters.
If they are not showing up in notepad I’d whatever you use to edit files have a look at it through an online editor if you have one, but I’m pretty sure they can be seen just opening the files in notepad or wordpad.
Thanks for using my script!!
Jamie.
good idea, but no. The editor is utf-8 and I have checked all files on the host too with vi. Nothing to bee seen there. I also deleted all lines except code and html from the index file. I have also tried three different versions of jquery.
Hi Jan,
it is defineatly in one of the files, i have seen this before.
Can you point me to the URL so i can have a look for myself?
Jamie.
cheers man, indeed…
[root@test 3]# cat index.htm
<!DOCTYPE html PUBLIC “-//W
Deleting this row in any editor still kept the garbage.
big thx, Jan
Hi again Jan,
Yes that looks like i thought it might, ha.
Which editor are you changing this line in?? vi/emacs??
Sorry this is taking a while to debug – it is the editors adding things in.
Have you got access to cPanel or a control panel with a file manager in it? ie: you can see the raw file inside a ‘textarea’ box. I am guessing if you change it there it may bypass the editor – give that one a go and let me know.
Good Luck,
Jamie.
Hello John.
The problem with your query is that the quotes are not the ones that should be in SQL… try this:
$query = $db->query("SELECT value FROM countries WHERE value LIKE '$queryString%' LIMIT 10");Jamie.
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
thanx
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
Hey I’m having a problem getting started with this. I’ve implemented all the code, I just can’t seem to post my data properly. Every time I try to access the data I’ve typed in in the rpc.php file, it says that variable contains no data. What could this mean?
Guys like me need guys like u
I spend about a whole night to get the up and down key functional and the enter key for selecting it and it stil doenst work for me.
Is there any way u can help me with this ?
Thakns!
nice! thank you. it works. but how do i position it below the input-field ,ontop of the form so that the lower elements of the form will not jump down?
and how do i use it for not just one input-field but 4 fields in one form _without_ writing an extra rpc.php and fill-function for every field?
I too, would like to figure out how to get the arrow keys working for this script. Great job, BTW!!
Its might be causeing problems with this blog form. I had a hell of a time getting firefox to stop trying to fill in fields for me.
Also is the msqli bit for a normal 4.0 5.0 mysql database or is mysqli totally different from mysql?
hello,
jamie thanks for the suggestion, works perfectly.
$query = $db->query(“SELECT value FROM countries WHERE value LIKE ‘$queryString%’ LIMIT 10″);
thanks for the superb script can anyone post, how can we have the name of city also displayed using this.
iam looking at providing auto-complete for list of cities for a specific country only.
any suggestions
I’m running into results that have a special character in them (like a single quote). They show up in the list, but are not clickable. Any thoughts? I’m thinking it needs to use:
mysql_real_escape_string()
Nice work
I got a question, just tooked the script and i have something to ask:
Can i change this line :
$.post(“rpc.php”, {queryString: “”+inputString+”"},
to :
$object_name->function_name(inputString)
i know there is another function, but how is easier for me to do so that i am using a function from a file and not a hole file for the process? the php function i will do it by myself.
Thanks!
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
thanks a log.
it is useful
[...] AutoCompleter (Tutorial with PHP&MySQL) [...]
Hi Jamie,
i really like the style of this, however my web host does not support php5 and im not good enough at php to convert it myself (ill have another stab later). so was wondering if you could send / post the php4 version of rpc.php.
many thanks,
Martin
hello everyone!
thankyou for all your comments and track-backs.
I am finally going to make all you PHP4ers happy; I have started the PHP4 version of the RPC file, so no need to try to re code it yourself.
I’ll post a link in the comments and at the top of this page in the next few days!
Jamie
top man. much appreciated.
This is cool man.. I m starting off on php, so this is really helpful.. I’m porting it to PHP4 as well, ‘ll wait for ur post to verify mine..
CHEERS!
[...] Autocomplete – jQuery ajax [...]
Really too good…
Hello, thank you for this great script
I was wondering if you could write how to modify the script so that it can read values from multiple tables, for example, script must read column ‘value’ from table ‘countries’ and column ‘value1′ from table ‘city’, etc.
Thanks in advance!
[...] AutoCompleter Tutorial – jQuery(Ajax)/PHP/MySQL, show you how and why it works, knowing about this enables you to [...]
Hi,
do you have a clue about why the submitted string is not inserted into the $_POST array?
Thanks,
Stine
I’m trying to adapt your great and well documented script so that I can cascade one search off another (country–>state–>city) but I’ve run into a spot of bother.
What I’ve done is:
1. to duplicate rpc.php and call it state.php so I can search my database for the state.
2. duplicated the javascript and renamed some of the names/functions (not really knowing what I am doing)
3. duplicated the html code and renamed some things. (variables?)
My problem is:
1. when I type the state, the selected value ends up in the top box not the bottom one. What do I need to change?
2. I haven’t worked out how to pass my country code to the search of the state yet.
You can see what is happening here:
http://notsoniceduck.com/autocomplete/index1.php
Any suggestions or help is greatly appreciated.
the code I used is: (rpc.php and state.php are only fror different tables and not posted here)
Ajax Auto Suggest
function lookup(inputString) {
if(inputString.length == 0) {
// Hide the suggestion box.
$(‘#suggestions’).hide();
} else {
$.post(“rpc.php”, {queryString: “”+inputString+”"}, function(data){
if(data.length >0) {
$(‘#suggestions’).show();
$(‘#autoSuggestionsList’).html(data);
}
});
}
} // lookup
function fill(thisValue) {
$(‘#inputString’).val(thisValue);
setTimeout(“$(‘#suggestions’).hide();”, 200);
}
// changed name of 2nd javascript
function lookupstate(inputString1) {
if(inputString1.length == 0) {
// Hide the suggestion box.
//changed #suggestions to #suggestions1
$(‘#suggestions1′).hide();
} else {
//+inputstring changed to +inputstring1
$.post(“state.php”, {queryString: “”+inputString1+”"}, function(data){
if(data.length >0) {
$(‘#suggestions1′).show();
$(‘#autoSuggestionsList1′).html(data);
}
});
}
} // lookup
function fillstate(thisValue) {
//changed #inputstring to #inputstring1
$(‘#inputString1′).val(thisValue);
//changed #suggestions to #suggestions1
setTimeout(“$(‘#suggestions1′).hide();”, 200);
}
body {
font-family: Helvetica;
font-size: 11px;
color: #000;
}
h3 {
margin: 0px;
padding: 0px;
}
.suggestionsBox {
position: relative;
left: 30px;
margin: 10px 0px 0px 0px;
width: 200px;
background-color: #212427;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
border: 2px solid #000;
color: #fff;
}
.suggestionList {
margin: 0px;
padding: 0px;
}
.suggestionList li {
margin: 0px 0px 3px 0px;
padding: 3px;
cursor: pointer;
}
.suggestionList li:hover {
background-color: #659CD8;
}
Type your county:
<You will need more than 3 characters to make the search work >
Now for the state lookup
Type your state (once you have filled in country):
<You will need more than 3 characters to make the search work >
Back to country only list
Great… something I wanted to do for a while.
I have made a small change so you can search out of order. For example, if you search for Uni, or search for King, then United Kingdom comes up. I found that if you search for King Uni then it doesnt come up with any results.
This is just the code I changed, comments have been striped out to save space…
I moved the sql statement in to a string, then split the querystring using space as a delimiter, then using the query string array, I added several searches from the same coloumn
__________
if(strlen($queryString) >0) {
$qu=split(” “,$queryString);
$sql=”SELECT value FROM countries WHERE “;
for ($i=0;$i<count($qu);$i++){
$sql.=” lower(value) LIKE lower(‘%$qu[$i]%’) “;
if ($iquery($sql);
——-
still… thanks…
hehe. got that wrong… missed out the } so where its
$sql.=” lower(value) LIKE lower(’%$qu[$i]%’) “;
if ($iquery($sql);
it should be
$sql.=” lower(value) LIKE lower(’%$qu[$i]%’) “;
}
if ($iquery($sql);
[...] 25. Auto Completer [...]
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
Hi Jamie,
This auto complete thing is great although i’m having a problem.
When i type in some thing and the drop down suggest lists displays for some reason above the first suggestion there is a mystery bit of writing.
Also is there a way to limit your results for instance im searching a table of surnames so for a common surname such as brown i would only like it to appear in the suggest bar once.
Any ideas how to fix it?
Many thanks
Hi,
fixed the first problem it was the alt=”upArrow” that was appearing in the drop down.
However id still like to know how to limit the record to remove duplicate suggestions.
cheers
Hey,
thanks a lot for this really nice tool, very good work
But one thing is buggy: I have problems with “Umlaut” / mutated vowel (correct word? Its from the dictionary).
What I mean are letters like ä ö ü.
I checked the PHP-Script – if I directly set $queryString to e.g. “Mü”, it shows me the correct results (in this case: “München” / german name for Munich).
Perhaps the problem is in the javascript, while processing the request onKeyUp() ?
Im not very good in Javascript, sorry
Can you help me?
Thanks a lot, Frank.
os va el ejemplo es q no consigo q funcione
abrupt withdraw symptoms from wellbutrin…
Click on image below to visit wellbutrin Online Page
Bupropion is used for the prevention of seasonal affective disorder,[45] and has been approved by the FDA for the latter indication.[46] There is considerable disagreement regarding whether the addit…
[...] Autocomplete AJAX Select Drowdown with ID AutoCompleter Tutorial – jQuery(Ajax)/PHP/MySQL Yahoo! AutoComplete jQuery Autocomplete Mod FaceBoox style autosuggest with jQuery Implementing [...]
i have a problem with this tutorials in my php code.
can i email you.
regards,
koko
Wow! That’s what I was looking for! Brilliant! Many thanks for the author! Apart of security issues, that’s cool!
WooWw …
AWEsoMe …
I Like it, that’s very nice …
ThaNkz …
hi when the text is displayed the enire bg is black
and i cannot see any thing, but i get the dropdown list that is completely black and i cannot see the text but there is no problems with connection the size if the dropdown is accoriding to the items but the only problem is the bg iblue and i cannot see the text
plz help
i use MYSQL database
sorry i have solved the problem
thankyou for the script
Is there a way to send multiple POST values to the rpc.php file?
thanks bro
[...] | Spurl | StumbleUpon jQuery Tutorials 1. jQuery Crash Course 2. Getting Started with jQuery 3. AutoCompleter Tutorial 4. Multiple File Upload Magic 5. jQuery for JavaScript programmers 6. Easy Ajax with jQuery 7. [...]
[...] AutoCompleter Tutorial [...]
i ‘ve problem….i try to submit form after getting the value needed but it wont pass the value….how to to it? im using php
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
Fabulous. As a web dev student, this is the kind of thing that can make my projects more real world.
Thanks for your help
t3rry
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
buttice mark unclaimed funds…
buttice mark unclaimed funds…
Hi. Somehow it’s not working for me. Can you help pls? I downloaded, changed my db name, password, etc, but when I try to type something in the input box, it shows me the entire PHP file starting from “real_escape_string($_POST[’queryString’]” i.e. the PHP file doesn’t appear to be processing. Do you know what can be my problem?
Hi!
How can I add another variable… example: function lookup(inputString, var01, var02, var03){ ..}
I also need this variable at the rpc.php script, so it is necessary to pass it at the call “$.post(“”,”",”"); … but how?
Thanks,
Luke
hi
good work
i m havin a prob in de above application
u can only select de names from de list wid de help of de mouse
u can not do de same using up or down arrow key
waiting 4 ur reply
thnx
Hi
It’s a great script, but what if you have 2 inputfields? Becaus i want to use it for 4 fields, but it always give a suggestionbox by the first field, and all the words were pasted in the first field.
Jamie, great script. I got it working with other sample values.
Would you know how to take the information now filled in via the suggestion box and make it query the same database, ie if we were using the country example to post to the html page, via ajax the currency, temp,major city ( all stored in same table on database)
What do i need for extension in php.ini fpr making the database connection to work with my autocomplete?
[...] AutoCompleter (Tutorial with PHP&MySQL) [...]
Hi
Great script!
I modified the JS to allow for multiple fields byt adding a target attribute.
I needed then to modify the rpc to include the target when clicked
Have a look
–Javascript changes —
function lookup(inputString,target) {
if(inputString.length == 0) {
// Hide the suggestion box.
$(‘#suggestions’).hide();
} else {
$.post(“/ajax/physical/”, {part: “”+inputString+”",target: “”+target+”"}, function(data){
if(data.length >0) {
$(‘#suggestions’).show();
$(‘#autoSuggestionsList’).html(data);
}
});
}
} // lookup
function fill(thisValue,target) {
$(‘#’+target+”).val(thisValue);
setTimeout(“$(‘#suggestions’).hide();”, 200);
}
—end—-
—PHP changes in RPC—
echo ”.$row['SUBURB'].”;
–end —
–HTML changes —
—end –
so what this means is dependsing on which input box you fill in clicking on the results will update the correct input thus allowing multiple inputs
[...] AutoCompleter Tutorial – jQuery(Ajax)/PHP/MySQL [...]
y que pasa con las teclas up y down?? no funcionan :S
A sugestion for Firefox user is change the html form to this:
Thanks
still show ‘’ here … only in firefox WHY???
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
How to solve that issue ==> 
And keyboard arrows ??
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
Nice tutorial, its quite like yahoo and google, but this can get very annoying at times.
Hi
I get an error saying:
Parse error: parse error, unexpected T_STRING, expecting ‘,’ or ‘;’ in
The line which gets the error is
echo ‘value.’‘);”>’.$result->value.‘’;
Does anyone have any suggestions
Oh yeah I forgot to mention Im using PHP4 if that helps
Sorry the line with th error is as follows:
echo ‘value.’‘);”>’.$result->value.‘’;
When I try to type anything in the box I just gets this
real_escape_string($_POST['queryString']);
// Is the string length greater than 0?
if(strlen($queryString) >0) {
// Run the query: We use LIKE ‘$queryString%’
// The percentage sign is a wild-card, in my example of countries it works like this…
// $queryString = ‘Uni’;
// Returned data = ‘United States, United Kindom’;
// YOU NEED TO ALTER THE QUERY TO MATCH YOUR DATABASE.
// eg: SELECT yourColumnName FROM yourTable WHERE yourColumnName LIKE ‘$queryString%’ LIMIT 10
$query = $db->query(“SELECT game FROM gameinfo WHERE game LIKE ‘$queryString%’ LIMIT 10″);
if($query) {
// While there are results loop through them – fetching an Object (i like PHP5 btw!).
while ($result = $query ->fetch_object()) {
// Format the results, im using for the list, you can change it.
// The onClick function fills the textbox with the result.
// YOU MUST CHANGE: $result->value to $result->your_colum
echo ‘game_id.’\');”>’.$result->game_id.”;
}
} else {
echo ‘ERROR: There was a problem with the query.’;
}
} else {
// Dont do anything.
} // There is a queryString.
} else {
echo ‘There should be no direct access to this script!’;
}
}
?>
The script dosen´t get anything out of my database. I cant find whats wrong. Please help.
Hi there,
Can somebody help me about inserting data into the database by auto insert,
1. once you type the information to the textbox then after typing, transfer to another textbox.
2. this will auto insert or update the data.
Please help, i am new to ajax.
thank you very much, your help is very much appreciated.
regards,
wizzit ventures
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
Cant view the source code in jquery-1.2.1.pack.js
Pls advices.
Hi all,
First of all thanks for this lovely little tutorial..
I downloaded the complete sourcepack and entered my db credentials and run the sql query.
Im only getting this error:
ERROR: There was a problem with the query
I guess it must have something to do with this line;
// YOU MUST CHANGE: $result->value to $result->your_colum
echo ‘value.’\’);”>’.$result->value.”;
}
I just dont understand what to change.. which column do you mean?
Looking forward to a solution, thanks!
For those who wants to remove the firefox autocomplete default box, you can use the attribut AUTOCOMPLETE=”off” to your form html entity.
i want to use two text box can any body help me.
Can someone help with this? I cant get the li hover to work on ie7, here is my css
.suggestionsBox {
position: absolute;
left: 650px;
top: 30px;
margin: 10px 0px 0px 0px;
width: 200px;
background-color: #212427;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
border: 2px solid #000;
color: #fff;
}
.suggestionList {
margin: 0px;
padding: 0px;
}
.suggestionList li {
margin: 0px 0px 3px 0px;
padding: 3px;
cursor: pointer;
}
.suggestionList li:hover {
background-color: #659CD8;
}
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
Hi ,
Good one this, but we can do this function using ajax only. So what difference between ajax and your ajax+jquery application? any think advantage there?
alopecia homeopathy complete hair loss…
alopecia homeopathy complete hair loss…
ymca in mobile al…
ymca in mobile al…
Great stuff. I appreciate your hardwork on this.
Tried this, and although am sure it works and is easy to follow and understand, even for a non-php developer, has anyone used this with a PHP page, instead of an HTML one? If so, is there anyone willing to share an example of how to implement it?
Thanks
Martin
Me again!
I managed to get it to work (had forgotton to set the query time from 10 seconds in mySQL – doh!) Only problem I have is that it lists the results I’d expect, but when you click or hit enter, there is nothing sent back to the textbox, so it’s empty.
I’ve taken your example, updated the database login details, and changed the two instances of ‘$result->value’ in the displaying of the suggestions, and nothing else, so am not sure why it doesn’t work.
Is there something I’m missing?
Thanks again – very cool sample.
Martin
Jamie,
First of all, great script. It was just what I was looking for and it was explained very well. I was wondering, however, when you enter a result that is _not_ in the database, it still displays the results that are similar for the first few letters. For example, if you entered “Great Britain” for the search, it will still suggest Greece, Greenland, and Grenada, even though those results are only similar up to the first three letters. Is there anyway to make the suggestions box disappear if the result is not found?
Thanks,
Dan
animated powerpoint templates…
animated powerpoint templates…
girlsonvideo com…
girlsonvideo com…
Jamie,
Sorry for posting again, but I was wondering if the PHP4 version was available yet. Have you had a chance to complete it?
Thanks,
Dan
[...] 16. AutoCompleter Tutorial [...]
Hi all! here it is the php5 & mysql version, there’s only one problem, i can make it run the onclick fill function =( please heeeeeeelp!
0) {
$result = mysql_query(“SELECT value FROM countries WHERE value LIKE ‘$queryString%’ LIMIT 10″);
if($result) {
while ($row = mysql_fetch_assoc($result) ) {
echo “”.$row['value'].”";
}
}
}
else{
echo “ERROR: There was a problem with the query.”;
}
}
?>
D**n, it didnt paste well =( anyway here its a rapidshare link with the source :
h**p://rapidshare.com/files/119818134/autocomplete.zip.html
please any help with the onclick fill function =( please heeeeeeelp!
Thanks a lot Jamie.
Im know something in php and mysql
But I zero about about javascript.
I was searching for this code for a long time for developing an inhouse db app.
It worked well for me.
Thanks Once again….
[...] AutoCompleter Tutorial – The AutoCompleter tutorial teaches you how auto completion of input fields can be accomplished. [...]
AJAX Examples…
Hier eine Liste mit Beispielen wie man AJAX einsetzten kann.
Wobei ich aber bisher jedem geraten habe, AJAX nur dann einzusetzten wenn es wirklich nötig ist.
Also nicht verwenden weil es “cool” ist. Das geht dann nach hinten los.
25 Excellent…
private photos…
private photos…
relient k guitar tabs…
relient k guitar tabs…
[...] ?????? ??google??? AutoCompleter tutorial [...]
the suggestion list div tag is expanding so the other contents in form are moving down.. is any way to display the contents of div tag over the form fields.
Hi Jamie… i really need your help… i downloaded your source and i cant use he…. if u can contact me by e-mail to I send to you “my code”…
Thanks []
[...] 16. AutoCompleter Tutorial [...]
zelless1…
zelless1…
who invented peanut butter…
who invented peanut butter…
like it says on the mac’donalds advert, da da da da da.. i’m living it
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery Plugin. ???(Inline Edit & Editors)jTagEditor. WYMeditor. jQuery [...]
[...] ? captcha ile kullan?n14.Ajax Login Form15.Yaz?lar için Ajax efekti | Demosu burada.16.Form Tamamlay?c? | Demo burada 17.Auto-populating Select Boxes using jQuery & AJAX | Demo burada.18.Ajax [...]
Hi Jamie, Im from Brazil and I really liked you code, It’s the best filter when we work with many fields at a page with a database connection.
It worked perfectly!!!
Peace from Brazil
Higor Vaz
ps. have you got any knowledge at ActionScript?
Hi, great script but I have wierd results. It shows a black box with “transparent” results, that means, I can see a list with bullets in IE but no text and in Firefox appears the same black box without bullets and no text.
I removed the CSS3 code with no positive results.
-PHP Version 5.2.2
-mySQL Version 4.1.22-standard
[...] 16. Form Tamamlay?c?: http://nodstrum.com/2007/09/19/autocompleter/ 17. Auto-populating Select Boxes using jQuery & AJAX: [...]
Really good post…
I had one question….I see all the examples with just one txt box…How can i make this work with 2 text boxes?? Say one for country and other for city??
yes, sugam has posted exactly what I was thinking about. yes, because it would be great if we had this country text box, then the city whose suggestions wud be based on the country selected and so on for location, street and so on.
well, yes a bit over-aimbitious but at least narrowing down of locations inside a country?
very useful very powerful
Love the script. Good job. Got it to work in 2 minutes. Keep up the great tutorials.
hi Sugan, Swapnil acharya and others who are looking
for more than one text box ….like country->state->city
is possible by using “callback”
here is important piece of code …that you need to adopt
eventDateCallback(element, entry) {
//return entry + “&call_pp2=” + document.add_call.call_pp2.value;
return entry + “&second_name=” + document.getElementById(’second_name’);
}
#———————
//
look
http://horde.greendragonempire.com/news/276-scriptaculous-ajax-autocompleter-callback-example.html
ajax stuff was missing in my previous post…, but you can see the same by following the link i mentioned in the previous post
new Ajax.Autocompleter(“search”, “hint”, “/ajax_autocomplete/server.php”,
{minChars: 1, frequency: 0.5, indicator: ‘indicator1′, callback: eventDateCallback}
);
Hi Jamie,
. I was just wondering if I had to have permissions or something to use these codes in my project.
Really helpful codes
[...] AutoCompleter (Tutorial with PHP&MySQL). [...]
Hi!
This is a very good script! THX!
But….
I have a problem…:-(
I wan’t 2 search boxes in one site, but if i stand in the second searchbox and select a country (example), the code write the data in the first searcbox. ID’s are diverse…
Please help anyone!
Thank you very much!!!!!
Hi Jamie,
first of all, great script!
thanks for taking the time to show it here.
my problem:
the script works fine except with “hebrew” queries.
for example: if i have an english query “apple” it works while typing “a” in the input box.
however, if the query is in hebrew language it stats “ERROR: there was a problem with the query”.
i’m a newbie in mysql and php and so couldn’t figure out the problem yet.
i will appreciate if you could help me here.
thanks
[...] Demo – Pagina oficial [...]
Ok im bout to pull my hair out, mianly cause of the fact that i dont know ajax/java very well and im having a hard time. This is a killer script and if i can get this ONE thing working then im good to go.
I have the script pulling cities in my database (mysql) Its pulling everything perfectly, thats not my problem.
I need to post the ID (cid) of the city into another box in the same form the autocomplete is in. It has the tag ID=”cid”.
I can get the data to copy to the cid textbox but i cant get JUST the id of the city into that box.
PLEEEASE help! Hopefully somebody has done this already. I really need this to work.
Thanks
-Bo
Hi, Nice Code.
I want to ask 2 things
a) Is it possible to use arrow keys to select an item from drop down? If yes, how?
b) How to change style of the ajax menu?
Thanks
–
- Riz
http://www.PDFonFly.com
I have noticed a bug .. If I type la ( in your demo ) it shows “Lao People’s Democratic Republic” as first option. I have tried to click on it several times but It is not working.
I think there’s some problem with single quote ( ‘ ) .. what u think?
–
- Riz
http://www.PDFonFly.com
i’m pulling out my hair too.. i remember getting it to work once before.. but omg… can someone please compile a php4 compatible code?
I’ve got it so that it outputs:
Vanuatu
when it should be:
Vanuatu
the quotes around “Vanuatu are missing and I don’t know why or how to get it back…
sigh.. stresssedd out.
[...] AutoCompleter (Tutorial with PHP&MySQL). [...]
[...] AutoCompleter (Tutorial with PHP&MySQL). [...]
Hello,
Sorry my english is not very good.
I have a problem with autocompleter. I search French town .results tips are black and font color is black also. It’s curious, no?
see here:
http://labospip.plugandspip.com/spip.php?page=cherche
and search : Lyon
If you have an answer to my question , i’m very happy
Oh yes i’ve not seen :
YOU MUST CHANGE: $result->value to $result->your_colum!
[...] AutoCompleter (Tutorial with PHP&MySQL). [...]
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
Doens’t work
: (-
Hello everyone;
long time no speak! Just wanted to thank for (almost) everyone for helping eachother out with the scripts i wrote – i do keep going through the spam comment list approving people code (it gets marked as spam for some reason).
I know that fitting other people apps into your own websites is sometimes a hard task, especially when it comes to fiddeling around with CSS
So thank you for sticking with it!
If you do have a problem i definatly advise having a quick run through the comments as they cover loads of problems people have uncovered!
As you can see i havent posted in a Looooong time, but with a full time job and my 2Big2Send project; its hard to make time to get on here!
I do plan to keep adding new tutorials – there is a good one on the way (file upload progress; which doesnt require special server software!)
So watch this space!!
Thank you for the continued support!
Jamie.
Hi! Going to give you a tip for the PHP4 problem.
I am using the MySQLi function in PHP5 which allows $myQuery->fetch_object()
In PHP4 you have to use the old style functions (not OOP stuff).
so you can get stuff by doing.
$result = mysql_fetch_assoc($myQuery);
Then just get your results back by
$result['MyColumnName'];
Hope that helps people!!
Jamie
Hey Jamie
My Comments were not spam and so werent BoNiggy’s.
Why delete them. You seem to be pretty uptight for a person running an open thread.
I just want an answer of why does your script push my table contents down and is there a way around for table based pages ? Tough question?
People a better solution is JQuery Autocomplete
Please try that. This script is bugful.
Hello Khuram,
I have no qualms about an open thread, but i do not want people bad mouthing my script as bad as you and BoNiggy did.
I know there are loads of other scripts out there, the JQuery AutoComplete is very well maintained! but i am glad that people are using mine rather than others.
As for answering your question, it is just a case of getting the CSS correct, in my example the code did exactly what you are requesting, it uses CSS styles divs and not tables, i´m not a fan of tables and therfore cannot offer any advice on how to structure them so the CSS correctly formats them.
I am sorry that you have had so many problems but the fact of the matter is that many other people have successfully got my script woring on their website
Good luck!
Jamie.
HI, need help, i want to add to this script a onarrow up and down key press, but i dont know how;
I have this script in php v4 .
Can somebody help me ??
Hi all,
Can any one suggest how we can make this code for multiple selection in input box like facebook compose message page.
thanks
the best autocomplete tutorial i have seen.. thanks for making the tutorial very specific. the comments are also very useful. nice job guys!
If, in the php-file, I change $_POST to $_GET and call the script directly, I’m having no problem recieving the rows beginning with Å, Ä or Ö in my database. However, if I run the script from the html-file (letting the script looking for $_POST) I cannot retrieve any rows beginng with Å, Ä or Ö. Any suggestions would be appreciated.
Its a piece of crap
(Sorry for my english)
HI Jamie
Need help
im a noob in javascript, and i want to add a navigation with up and down key.
Can you help me??
Please ?!?!?!?!
Nice Stuff.. Can you say me how to do it with JSP and Python?
Here the solution for the Brazil characters:
In the rpc.php :
———-
$db = new mysqli(‘adress’,'user’,'pass’,'database’);
$db->query(“SET NAMES ‘latin1′”);
$db->query(“SET CHARACTER SET latin1″);
.
.
.
if(isset($_POST['queryString'])) {
$queryString = $db->real_escape_string($_POST['queryString']);
$queryString = iconv(‘UTF-8′,’latin1′,$queryString);
.
.
.
// YOU MUST CHANGE: $result->value to $result->your_colum
$strUTF = iconv(‘latin1′,’UTF-8′,$result->your_column);
echo ”.$strUTF.”;
————-
thnx…it worked in my code…rock on….
Hi,
Any help to get several auto-complete fields in the same form ?
For example artists, medium…
Thanks in advance,
Daniel
[...] Hope they help. jQuery Tutorials 1. jQuery Crash Course 2. Getting Started with jQuery 3. AutoCompleter Tutorial 4. Multiple File Upload Magic 5. jQuery for JavaScript programmers 6. Easy Ajax with jQuery 7. [...]
Hi Jamie,
ty for the good tutorial…
there are many question about getting the up/down keys to work… is there a solution?
And there is another small thing: the suggestions List still “exists” when i type in words that do not exist in the db query…
small example from your demo: if i type in “vanuaaaaaaa” “Vanuatu” is still displayed. Is there a possibility to close the suggestions box in the case that there are no matches?
thx in advance…
hi,
can we do paging with this autocomplete things.
Thanks,
Srinivasan M
hi
i get an error which says mysqli class not found does anyone
know what im doing wrong?????????
Como puedo utilizar este script con MYSQL, not lite?
Any idea?
Thx
i have a problem…as I use this script with MYSQL 5 (no lite)?
Thx in advance
Hi Julio,
I would love put the Up/Down functionality into my script, but i have not done any research.
I know alot of people have requested it, so i may update it in the future….
In the mean time i’d search Google for “javascript + keyboard key event”
Jamie.
Hello Geetha,
I have never done any coding in JSP and my Python knowledge is next to nothing, so sorry not going to port it.
I am sure there are JSP/Python examples out there – Google is your friend!
Jamie.
Pix,
Thank you for getting it to work with Brazilian/Foreign characters
Hello Daniel,
Sorry not sure what you mean by multiple fields, im sure you could hack it to use different HTML IDs to show the results?
Jamie.
Srinivasan,
Having pagination in an auto-completer kind of defeats the purpose of it
Jamie.
Hi “sum1″
You’re getting that error because your PHP environment does not have MySQLi installed.
This is probably because you are running PHP4, the main tutorial i wrote is for PHP5 which has MySQLi enabled.
Somewhere in the comments above there is a way to convert it to work in PHP4
Jamie.
any idea how to use with mysql 5?
or …how to run onclick fill function?
\”\” . $row[\'value\'] . \”\”;
thx advance
Hi Jamie,
Thanks for your answer
Let say on the same page I’d like to have several auto complete fields.
I already have country, I know want to have also cities from a table called “city”.
I’m looking for the config of rpc.php and, in the html file, of the input file.
By the way, my final goal is to be able to update each database (country & city) if I add a new item that is not yet in the db !
Daniel
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
I couldn’t do that with PHP4 version.Can anyone send full of php4 code.Thx
how to use with php4??…
Faith… look this
http://rapidshare.com/files/119818134/autocomplete.zip.html
but i have problems with onclick fill function… anyone help?
thx
ola amm zoi la niña maz ermoza de todo el mundo
si si y soi la maz afortunada pz claro tengo komo novio al niño maz ermoxo y lindo toda xava desearia tener si klaro amorxis t amo kon toda el alma si k si… erez la luz k alumbra mi kamino sin tu amor no seria nada
klaro k si xikoz (as) kiero k todos lo sepan
EMANUEL t AMo kon todo el hert jaja cprazon mi niño xulo
vales mil weno m voi
GRATZ x todo
Biie Biie
x zierto m enkantan laz estrellaz si k si
hello
excellent script
how can I modify to fill other field with other column when I clic over suggestion box??
# real_escape_string($_POST['queryString']); // Is the string length greater than 0? if(strlen($queryString) >0) { // Run the query: We use LIKE ‘$queryString%’ // The percentage sign is a wild-card, in my example of countries it works like this… // $queryString = ‘Uni’; // Returned data = ‘United States, United Kindom’; // YOU NEED TO ALTER THE QUERY TO MATCH YOUR DATABASE. // eg: SELECT yourColumnName FROM yourTable WHERE yourColumnName LIKE ‘$queryString%’ LIMIT 10 $query = $db->query(“SELECT projektname FROM projekte WHERE projektname LIKE ‘$queryString%’ LIMIT 10″); if($query) { // While there are results loop through them – fetching an Object (i like PHP5 btw!). while ($result = $query ->fetch_object()) { // Format the results, im using for the list, you can change it. // The onClick function fills the textbox with the result. // YOU MUST CHANGE: $result->value to $result->your_colum echo ‘
# ‘.$result->projektname.’
‘; } } else { echo ‘ERROR: There was a problem with the query.’; } } else { // Dont do anything. } // There is a queryString. } else { echo ‘There should be no direct access to this script!’; } } ?>
Hi,
I tried this application ! It’s working partially
when i hit one letter one textbox will be added. this will repeated. and
echo ‘There should be no direct access to this script!’;
this line shown at next text box.
How to create class for $db?
Please give me suggestion ASAP!!
Thank you
Ramesh.M
VST Hyderabad
[...] fameux tutoriel sur l’autocomplétion (en anglais) Tags : javascript, AJAX, jQuery, [...]
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
Si cambio la query por una tabla de mi bd no me muestra nada por q???
These two css lines are causing the css page to fail validation with w3c. Are these two css lines necessary? What are they for?
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
Hi, i’ve tryed to adjust the script to fit multiple inputfields using a target feature.
Atm i’m stuck at the fill function.
function fill(thisValue,target) {
$(‘#’+target+”).val(thisValue);
setTimeout(“$(‘#suggestions’).hide();”, 200);
}
This doesn’t seem to work.
Do you have any suggestions pls?
I’ve problems with onclick fill function with php4
$db = mysql_pconnect(“localhost”, “root” ,”", “test”);
if(!$db) {
echo ‘ERROR: Could not connect to the database.’;
} else {
if(isset($_POST['queryString'])) {
$queryString = mysql_real_escape_string($_POST['queryString']);
if(strlen($queryString) >0) {
$query = mysql_query(“SELECT Sirket FROM firma WHERE Sirket LIKE ‘$queryString%’ LIMIT 10″);
if($query) {
while ($result = mysql_fetch_array($query)) {
echo ”.$result['Sirket'].”;
}
} else {
echo ‘ERROR: There was a problem with the query.’;
}
} else {
}
} else {
echo ‘There should be no direct access to this script!’;
}
}
How can i solve this
compatible 100% php4 onclick fill function fixed ..thanks to me
0)
{
$result = mysql_query(“SELECT user FROM users WHERE user LIKE ‘$queryString%’ LIMIT 10″);
if($result)
{
//fetch rows from result set.
while ($row = mysql_fetch_array($result))
{
echo ”.$row['user'].”;
}
}
else
{
echo ‘ERROR: There was a problem with the query.’;
}
}
else
{
} // There is a queryString.
}
else
{
echo ‘There should be no direct access to this script!’;
}
?>
sorry i didnt appear in my preivious post
here is onclik function fixed for php 4 by gool54
echo ”.$row['user'].”;
change
then u have no autocompelete in any browser
autocomplete=off
in the input field
Maybe i can ask for help in this case again…
from my prior comment:
Regarding the search in the demo and also if i implement the code for my autocompleter:
if i type in “vanuaaaaaaa” “Vanuatu” is still displayed. Is there a possibility to close the suggestions box in the case that there are no matches?
Can anyone help with this?
thx
Very nice, Good job!
anyone have solution for drowpdown menu is pushing all html objects i tried z-index but not working??
Hi,
In addition to text, how to select the Id of the selected object. Much like key-pair values.
select countryid, countryname from tblCountries
Any ideas on how to get this done?
Hi Guys,
You can easily use this .js file to fetch data from database and integrate in the following script.
http://cssglobe.com/post/1202/searchfield-unobtrusive-search-field-solution
We simply need to include the .js script in searchfield.js and modify this.getListItem, to include the data retrieved from the database.
This gui is more intuitive and does’nt disturb the page layout.
thanks for the tutorial. very helpful. maybe you should put the mysql section at top because i was confused until i downloaded the file to see there was a .sql file
??
These two css lines are causing the css page to fail validation with w3c. Are these two css lines necessary? What are they for?
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
I’ve implemented the auto complete here on the “Shop by market” input box: http://www.wsmcms.com/
However, the suggestion box messes up all the rest of my CSS coding. When the box drops down it pushes my other content.
Can anyone point me in the direction of a fix?
I’ve tried playing with the z-index, but to no avail.
Serpico ; try playng with the CSS atribute “position:absolute”, or try other position atribute.
Hi, not very good with java or html, the rpc.php seems to be selecting the correct fields I want from a table because I can see the drop down box changing for different letters but I do not see the text or am able to select an option, I have seen a few posts asking the same question but no answers. Anyone know the answer?
Hi Jack,
If you happen to see a black box only instead of your suggest list, you could check the following line in rpc.php:
echo ‘value).’\');”>’.$result->value.”;
Replace ‘value’ with the column of your database you want to show in your suggest box.
Have fun!
Great script, by the way!
ok, just to give myself the answer and anyone else is interested in…
Problem was: suggestions box stay on top even if you put in smoething that first leads to a suggestion but then you type in something weird, ie “vanuaaaaaaa” and “Vanuatu” is still displayed.
Go into the java script part and put in:
$(‘#suggestions’).hide();
} else {
$.post(“fileadmin/autocom/rpc.php”, {queryString: “”inputString+”"}, function(data){
if(data.length >90) {
$(‘#suggestions’).show();
$(‘#autoSuggestionsList’).html(data);
}
else {
$(‘#suggestions’).hide();
}
});
play around with data.lenght > 90 with your own value…
i use 90 because there is fixed Text in front of the suggestions list…
hf
Hi Awin,
works great now, thank’s for the help.
[...] Si vous voulez intégrer l’autocomplétion à un de vos projets, il existe de très nombreux exemples sur le Web, par exemple avec Scriptaculous, Mootools ou JQuery (alt). [...]
Thanks guys. I fixed my problem. The suggestionsBox class needed to have a position absolute and the parent class needed to be position relative.
Next question, why don’t the curved boxes on the suggestionsBox appear in Internet Explorer. I reckon it’s something to do with my base href. Any thoughts?
Hi, thanks for share, excellent job! Sorry about my english, Could you post how can i use with several input fields and with paginate? Thanks again. God Bless you! Jesus loves you! Read the biblie!
[...] 16. AutoCompleter Tutorial [...]
i need php4 version for the rpc.phpo file ..it has not been included in the zip file..please do this favour for me…
[...] http://snook.ca/archives/javascript/jquery_plugin/ http://nodstrum.com/2007/09/19/autocompleter/ http://joanpiedra.com/jquery/greasemonkey/ [...]
[...] 16. Form Tamamlayıcı: http://nodstrum.com/2007/09/19/autocompleter/ 17. Auto-populating Select Boxes using jQuery & AJAX: [...]
0){
// Run the query: We use LIKE ‘$queryString%’
// The percentage sign is a wild-card, in my example of countries it works like this…
// $queryString = ‘Uni’;
// Returned data = ‘United States, United Kindom’;
// YOU NEED TO ALTER THE QUERY TO MATCH YOUR DATABASE.
// eg: SELECT yourColumnName FROM yourTable WHERE yourColumnName LIKE ‘$queryString%’ LIMIT 10
$query = mysql_query(“SELECT column name FROM tablename WHERE loc LIKE ‘$queryString%’ LIMIT 2″);
if($query) {
//fetch rows from result set.
while ($result = mysql_fetch_assoc($query) ) {
echo ”.$result['column name'].”;
}
}else{
echo ‘ERROR: There was a problem with the query.’;
}
} else {
// Dont do anything.
} // There is a queryString.
} else {
echo “There should be no direct access to this script!”;
}
}
?>
[...] AutoCompleter Tutorial – jQuery(Ajax)/PHP/MySQL [...]
Hi! Congratulations about this awesome tutorial! I still have some problems with it. I’m from Bulgaria and here we use Cyrillic characters. When i type somethink in cyrilic the suggestion div does not shows. Why? What is wrong?
Oh, my Lord, I’ve been giving you all my “THANK YOU”
That’s what I have searched for a long long time.
You make me remain calm and exciting spontaneously.
Love this, and thanks very much.
Well done, YOU
Hi. if you are still maintaining this tread, i would like to know how to make it compatible with danish carachters (æøå)
and i would like it to be on top of contents, instead of pushing it down.
and as a little feature, it would be nice to have a little ajax loading icon when it is loading, and a mignifying glas when not loading.
if you would like some money in return for this request, please let me know.
I’ve implemented this at http://www.wsmcms.com/ on the Shop by market input box. Can anyone see why the rounded boxes on the suggestionbox aren’t showing in IE?
HI!That has pretty! thank you!
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
Hi,
I have two questions
1.Do you know why does this does not work with apostropes ?
2.What do I need to make this work with the Irish language character set?
Thanks
Al
Absolutely wonderful script and so easy to use! This has saved me many hours of work
OK,
echo ‘Name).’\');”>’.$result->Name.”;
Solves the “‘ problem but I’m still no wiser on how to use the extended latin character set
”
echo ‘Name).’\');”>’.$result->Name.”;
this is a great feature, but I am pulling my hair our trying to get it to work.
Has anybody had any success getting it to work with charset=utf-8
Al
to get this script working with other charsets you should use the php command iconv…
just to give an example for the output… in this case the results stored in the db are latin1 but in need them to be in utf-8 when put into the list
echo ‘title).’\');”>’.iconv(“ISO-8859-1″,”UTF-8″,$result->title).”;
hmm, sorry, the above line of code is destroyed because of i dont know
hopefully will work now
echo ‘title).’\');”>’.iconv(“ISO-8859-1″,”UTF-8″,$result->title).”;
sry, doesnt work to post the correct line of code
Hi !
Am currently using this jQuery(AJAX) for my developments. I need to pass drop down selection box value to rpc.php file for view suggestions according to the selected drop down value if any one can know this thing please reply me.
Thanks.
Sanka Kolitha
Hello, i’m using this imba scriptlet on an variable base and it works great.
Somehow however…. it seemes that sometimes the clicked respons won’t go to the field.
This only happens on occassion and as far as i can see for no reason at all.
Most of the time it does what it’s supposed to.
Any suggestions on how to solve this or where the issue is??
Hey!
Great script! I had a question though, say I wanted to have it grab more than just 1 query,
$query = $db->query(“SELECT school_name FROM pligg_schools WHERE school_name LIKE ‘$queryString%’ LIMIT 10″);
When i start to search, works great, but some school names I have are duplicates, and so to specify the difference id like to include “school_city” and/or “school_zip” and/or “school_state”
How might I go about this?
i think you want “select distinct …”
I actually JUST figured it out but thank you!
was i right?
Yigor, where exactly did you put that javascript in to get rid of the box after there are no more relevant results?
Hi Brian,
i just extended the java script for this purpose. The script itself remains where is has to be, i.e: html-body of your site.
I uploaded the whole script to rapidshare. Just customize it for your own needs, there are still my variables in there. If you download the script and look into it youll see what i mean
http://rapidshare.com/files/145706489/autocom.txt.html
Greets
Jamie, you were right the first time round mate, one of the advantages of using MySQLi connections over standard MySQL is that you no longer need to add real_escape_string this is done for you automatically by the MySQLi connect….
how could i make this connect to MS SQL ??
rpc.php can have whatever you want inside, all this is really doing is make use of $querystring which is posted as you type. You can create any kind of connection to any database in any way you like, whatever rcp.php outputs is whatever appears in the originating page’s element. There’s no reason why MS SQL wouldn’t work at all. Just have the confidence to rewrite the page – it is essentially just one query.
I am assuming your query isn’t, ‘what is connection string for a MS SQL db?’
hi this tutorial is ok but my autosuggestedlist is remove to another position if i change resolutiot how to fix it. i want my autosuggestes under field after change resolution
Hello guys, just 2 questions:
1) what are all the consecutive open and closing braces following?
#######################
}
} else {
// Dont do anything.
} // There is a queryString.
} else {
echo “There should be no direct access to this script!”;
}
}
#########################
I cannot inderstand this statement (infact it turns me as an error when I run the page and type anything on the input field)
2) I assume you’re using the double quotation marks above keypad “2″ on the echo statement:
#################################
echo ”.$result['column name'].”;
##############################
BTW I’m using the PHP4 modified-version
Any help is highly welcomed!
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP MySQL). quick Search jQuery [...]
Hi Jamie,
Thanks for your codes, it has been very useful.
While I do not have any problems implementing your codes, I do face some problems making modification to it. I am tweaking the code so that it displays 2 values instead of one, for example, i want to display both the id and the country name in this format:
1
Singapore
or
1, Singapore
And when user click on it, it displays only the country name “Singapore”. Can this be done?
This script works great. Thanks!
I have one issue. If the colon character “:” is within any of the options in the suggestions list, the selection doesn’t appear in the textbox when clicked.
Any suggestions?
Thanks
Sorry it’s not the colon character. It’s the apostrophe character that’s causing it.
To resolve the single quote problem do the following…
replace this line:
echo ‘value.’\');”>’.$result->value.”;
with this line:
echo ‘value.’");”>’.$result->value.”;
I see that my post is not correct, charaters are missing, you can email me for the solution.
Thanks Robert. I just figured it out.
First put the result in a variable and then use addslash on it within a second variable.
$result = $result->value;
$resultslashed = addslashes($mygametitle);
echo ‘’.$result.‘’;
Thanks Robert. I just figured it out.
First put the result in a variable and then use addslash on it within a second variable.
$result = $result->value;
$resultslashed = addslashes($result);
echo ‘’.$result.‘’;
I now see what you mean, the code isn’t posting.
Basically I put the slashed one to replace the first $result->value and the non slashed in the second.
Muy buenas.
Le he dado ya cien vueltas al código y no entiendo qué ocurre. Cuando escribo en la caja de texto me sale la caja negra donde debían aparecer los registros de la consulta pero me aparece mi código PHP a partir de el 0 de esta línea: if (strlen($queryString)>0)
No entiendo qué ocurre. A ver si alguien puede ayudarme, gracias
Este es mi código:
0)
{
$cadena_consulta=”SELECT entidad FROM contactos WHERE entidad LIKE ‘”.$queryString.”%’”;
$resultado_consulta=mysql_query($cadena_consulta,$conexion_bd);
while($lista_contactos=mysql_fetch_array($resultado_consulta))
{
echo $lista_contactos["entidad"];
}
}
}
}
?>
What could be the problem if there is no response from the rpc.php.? I doublechecked the db connect, the right column settings, the query, I even checked the query in phpmyadmin to make sure its not that the problem but still I dont get any response.
is there any php.ini settings or anythings else I should change on the server ’cause I tried on localhost and it works there.
somebody plz help me
problem solved.
i’m trying to setup the script but it does not appear. i use a template file including another file with the form. i have added jquery-1.2.1.pack.js, configured rcp.php and included css but nothing… any idea?
thank you,
John
Has anyone got the onclick fill working in php 4? I tried the other solution posted a little earlier.
echo ”.$row['user'].”;
But then nothing appears in the suggestion box. I also am not sure how to use the addslash commend in php 4.
Any suggestions would be greatly appericated.
i solved my problem in post 340 but now what i see when i type in the box is a “?”… i’m typing greek using utf-8. any ideas?
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
can i add 2,3,4.. etc text boxes with auto fill?
#John 342:
after db connect try this
mysql_query(“SET NAMES UTF8″);
I think it will solve your problem.
hi i’m not able to select from drop down !! there is something wrong in CSS i suppose
It just does nothing !! I am using JSP !
sb.append(“”+result.get(j)+”");
out.println(sb.toString());
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
[...] AutoCompleter [...]
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
Is it possible to use more than one in a page? If it’s possible can you tell me how is this done? Thanks a lot
[...] AutoCompleter [...]
sorry,
Toturial
http://tutorial.crazycoder.cn
School
http://School.CrazyCoder.cn
Jamie,
Good Code the issue that i’m having is that I have connected the completer up to my own database called Debbie with the table addresses. My Coloum headings are Id, Street,Suburb,City,Postcode but when I go to search I don’t get the black drop down box with a non capital letter but I get it with a Capital. The box is displayed blank.
My query is:
$query = $db->query(“SELECT Street FROM addresses WHERE Street LIKE ‘$queryString%’ LIMIT 20″);
I want it to select the common street names as the person types it so the can select there street suburb city postcode.
But im stuck with why its not loading as the countries one works fine.
[...] Autocomplete – jQuery ajax [...]
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
[...] AutoCompleter Tutorial This tutorial produces a result similar to the preceding tutorial. [...]
[...] AutoCompleter Tutorial This tutorial produces a result similar to the preceding tutorial. [...]
[...] AutoCompleter Tutorial This tutorial produces a result similar to the preceding tutorial. [...]
[...] Components: Autosuggest ? AutoCompleter Tutorial – ??????????? ??? ????? [...]
Works perfect on Apache system but I can’t get it to work at all with IIS. Been trying for 2 hours now but can’t seem to locate the issue.
[...] AutoCompleter Tutorial This tutorial produces a result similar to the preceding tutorial. [...]
[...] AutoCompleter TutorialThis tutorial produces a result similar to the preceding tutorial. [...]
[...] Hallo, ich habe das Autocomplete Script von hier verwendet und die PHP Datei neu geschrieben… AutoCompleter Tutorial – jQuery(Ajax)/PHP/MySQL – Nodstrum NUn wollte ich wissen, was man ?ndern muss, damit man die Suchvorschl?ge nicht mit der Maustaste [...]
you can’t use arrows to navigate though suggests as in native (eg user name from password bank) inputs
@Lukas: you have to add
autocomplete=”off”
to the attributes of your input-field. So there are no more “Browser”-suggests. You can do it also with jQuery to separate JS from html.
[...] AutoCompleter Tutorial This tutorial produces a result similar to the preceding tutorial. [...]
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
Excellent work!
Hi,
Great code , indeed . But does anyone know how to do this
with mySQL instead of mySQLi ? I am getting errors like the
entire PHP code is printed when i write something in the
textbox.
hi ,
solved it and it works !
@prasad: i have the same problem, how did u manage it?
Great code! We’ll use some of this in one of our new projects. Later /Magnus
i was able to get this to work w/ mySQL … and i’d have to check my notes but i think i even got MS SQL to work.
someone still need it?
Great job! This works just as good or better than any other combobox that I’ve seen.
The problem that I’m having is that I’m dynamically adding text boxes as described at http://mohdshaiful.wordpress.com/2007/05/31/form-elements-generation-using-jquery/ and I’m trying to attach the fill() to any of the dynamic boxes. I can get a popup to display and drill down to any of the boxes, but I can’t get the selected item to attach to the dynamically created textboxes.
Anyone have any ideas to fill in the correct box with the selected item?
[...] AutoCompleter Tutorial This tutorial produces a result similar to the preceding tutorial. [...]
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP MySQL). quick Search jQuery [...]
@Jonathan: it would be nice of you if you can post the code, managed for mySQL here
[...] AutoCompleter (Tutorial with PHP&MySQL) [...]
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
I can not seem to get this to work for more than one text box? Target?
thx
hi
it is a nice script. i modified this to jsp and its working fine. But one problem i am facing. Suggestion list is not overlapping its strtching my td tag. I want to display this to the top of the page. Not within the . Please help me anyone
Thanking you
Vini
i tried to post my code using a local mysql environment but it’s awaiting moderation.
i also tried to get a 2 column query to work but it doesn’t seem to.
email me @ jonathan@jdusza.com if you’d like a copy of what i used. put “AutoCompleter Tutorial” in the Subject line.
It´s a great script i used in a proyect.
Good Job
[...] ?????? ???????? ???????????… ?? ???? ???? ???????? ??? ??? ?????????????? ??????? jquery autocomplete [...]
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery Plugin. ?????(Inline Edit & Editors) jTagEditor. WYMeditor. [...]
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
i have a problem that the post reponse status in firebug remains on loading… nothing happens.
This tutorial affects the designing of the pages which are below the div tags
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
Thanks,
it is a very nice tutorial, really. I wonder if it possible to have a list as popup or use SELECT tag instead of INPUT. I have a quite big form with meny input fields below the autocopleter filed.
I don’t want to degrage lokk of my form when a list is visible.
Thanks for any sugestions
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
This example disturbs the designing of the page. it should be like drop down which displays list over the page
hi, I have found the solution to the problem of the list, which moves the next fields down. Working with CSS so that the box (div class=”suggestionsBox”) release their static position and let other elements takes space. Example :change to the absolute positioning.
/ Jarandov
P.S. Jamie it is a really great example. Thanks
When I start typing there is nothing showing and I get this error( the yellow triangle with an exclamation point to the lwoer left corner of the browser)
Line 25
Char : 3
Error: Object Expected…
Oh and I get this also:
Line : 15
Error: ‘$’ is undefined
OK I fixed,
weirdly I just re-wrote the same thing -.-
anyways I get:
There was a problem with the query error.
I have teh same thing that I downloaded from the file. I just changed the values thats it…
Hi,
how can we select listing by keyboard??
Hi, There has been talk about having multiple input boxes to drive the output. There are some samples but what am not sure is how the html side of things need to be structured to do this?
Thanks
sir, i have tried using this script. i have php4. ur script did not work. then i copies and pasted ur php4 stuff. still i did not work. could you please provided me complete rpc.php file for php4? regards.
hi,
i have tired to download the file. but it is not working
Also would really love to have a COMPLETE file that will work in PHP4. Please, please, please.
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
I had several failed attempts to implement autocomplete in my site and at last, your tutorial helped me to succeed. Thank you very much..
Nice script, i use it on all my sites. Now i have a question. Is it possible to incl. pagination in de autocomplete box, or a button to go to the next result set.
Any way to using “GET” instead of “POST”?
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
[...] AutoCompleter (Tutorial with PHP&MySQL). [...]
Good Lord, I think I read through almost everyone of the comments here shaking my head. Some people just don’t understand the concept of websites. This script does exactly what it says it does, if you don’t know how to use it – hire someone or learn it. You’re not going to learn by complaining or spamming the comment section.
This script rocks, I’m going to find out how to enable the use of arrow keys right now and post it. I might EVEN google it, shmucks.
Thanks for the code(s)
Antonio
:Antonio,
When you get done figuring out the arrow keys, maybe you can help me figure out the “backwards d” that I saw somewhere else, then the “upside down d” that is below:
:p
db
i keep getting “lookup is not defined” in my error console
the only things i changed was the db access/query
also getting:
Error: syntax error
Source Code:
$(.#suggestions.).hide();
any suggestions?
thanks for the code and assistance
That was really nice code, i just needed to convert it to mysql, but it was really awesome… thanks dude….:)
[...] AutoCompleter (Tutorial with PHP&MySQL). [...]
Is it to possible to allow users to select item from the list by using the up and down key instead of forcing them to use mouse to select?
if possible to do that, can anyone please tell me what need to be done?
Thanks
[...] Autocomplete by AjaxDaddy jQuery Autocomplete Plugin with HTML formatting jQuery Autocompleter AutoCompleter (Tutorial with PHP&MySQL) quick Search jQuery [...]
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
Hi
Where is demo?
Thanks
the DEMO
http://res.nodstrum.com/autoComplete/index.htm
hey,
the mysqli code doesn’t work on my server, and I’d try to write only a mysql code. But I need help …. has everyone only the mysql rpc.php script and can send it on my mail-adress, please?
thanks a lot for help
Me ha sido muy útil.
Muchas gracias.
Thanks.
It is so easy.
[...] AutoCompleter (Tutorial with PHP&MySQL). [...]
hi,
plz help me.
echo ‘value.’‘);”>’.$result->value.‘’;
this line was problem.
selected list item doest place in textbox.
plz solve this problem.
Saranya, as it says im rpc.php:
// YOU MUST CHANGE: $result->value to $result->your_colum
My query is
SELECT town FROM towns
so the line should be
echo ‘town.’\');”>’.$result->town.”;
This section is different to yours:
->town.’\');”>’
Saranya, as it says in rpc.php:
// YOU MUST CHANGE: $result->value to $result->your_colum
My query is
SELECT town FROM towns
so the line should be
echo ‘town.’\');”>’.$result->town.”;
This section is different to yours:
->town.’\');”>’
I have a form with four input fields, each a different variable/value each reading a different db table and need to have an autocomplete on each. Do you have any suggestions on how to modify your code without having to rewrite the javascript code four times changing the id’s? Many thanks in advance.
Thank u pete clark. my problem was solved.
Hello, I have a problem with the code.
Please help me.
$db->query(“SET NAMES big5″);
$db->query(“SET CHARACTER SET big5″);
…
$queryString = iconv(‘utf-8′,’big5′,$queryString);
…
echo ‘m_name).’\');”>’.iconv(‘big5′,’UTF-8′,$result->m_name).”;
I can selecte list item like “Taipei” and “??”.
But I can’t select list item like “Taipei??”. It doest place in textbox.
Does anyone know what how to solve this problem? Please help me.
Thanks a lot!
Hello,
does anyone know how to highlight the typed characters in the suggestion list?
Any help would be really appreciated
!
Thank you in advance…
To highlight the typed characters, you need to change the line that you had to change in the rpc.php file:
echo ‘value.’\');”>’.$result->value.”;
Just before that line, make a new variable:
$highlighted_value=$result->value
Then, using strpos($highlighted_value, $queryString), etc., change $highlighted_value from, for example,
“catalogue” to “catalogue”
Then add your line:
echo ‘value.’\');”>’.$highlighted_value.”;
Hope that points you in the correct direction.
And no, I haven’t tested it, but it will work when you write the complete code.
Finally, set your CSS to display class highlighted as you want it to appear.
OK, I have no idea why my code doesn’t appear, when others appear to have done it OK, so I have re-posted it on my own site.
http://www.hotcosta.com/hotpage3.php
Thank you Pete Clark,
i will test your solution (hopefully) today
I did only read the first 200 comments but this is how i solved the problem with entering junk data like stockholgsfsgassagggfa. If you don’t want the results to ´stay´ you need to send the js something with the php script, this is how i did it:
while ($result = $query ->fetch_object()) {
…
// YOU MUST CHANGE: $result->value to $result->your_colum
echo ‘value.’\');”>’.$result->value.”;
$putify = true;
} if(!$putify) { echo ‘No match!’; }
Ohh, stop messing up the html… A blog with subjects like css, php, html etc with no html enabled in the comments? Why not convert the tags to & lt ; and & gt ; ?
The code again:
while ($result = $query ->fetch_object()) {
echo ‘[ li ] $result->imdb_moviename [/ li ]‘;
$putify = true;
}
if(!$putify) { echo ‘Ingen träff!’; }
Jamie, thanks for this code and tutorial, I now have this up and running on http://www.ringtones4all.com it works great using the position as absolute
Thanks again
Mike
[...] AutoCompleter Bau eines Autocompleters für Eingabefelder. [...]
is there any work around to not use mysqli my host has not got it eneabled?
You can use any backend database that you want to. I use simple MySQL commands, as that is what my database library uses.
Just change the relevant lines in rpc.php
What database do you have?
Great feature!
I would like to display multiple listboxes with autsuggestions.
For example I have a table called “movies” with the following column headings in the table: id, title, actor.
In MySQL:
1, Stargate, Mark Jackson
2, Rambo, Sylvester Stallone
In the searchbox I type: S
I would like to display 2 different listboxes in which the first one displays (title) Stargate and the other box displays (actor) Sylvester Stallone.
How is this done? Any suggestions?
Hi,
This script is fine but I just want to know where is the fill() means which file contains this and If I want to select the countries on keyPress then what code I have to do change and where.
I just want to know How can I use keypress while selecting the countries.
In script use fill(sel)
sel is a variable. you use any variable within fill() function in script.
u must use fill function withu argument.
I have to use up and down navigation key to select the country, how can I do this.
Thanks for the code and tutorial Jamie. Appreciate everyone’s feedback and help, however, I didn’t exactly find what I needed…
< Weak on Javascript+Ajax: how can I post more variables to the rcp.php script so that I can dynamically search columns and tables?
Thanks in advance!
First of thanks for your time tested code,
everything I have done works just as I needed it , however I have some unwanted encoding hexes that appear in the suggest box at the top , if you take a look at this bare bone example you will see it , weather it finds a hit in the DB or spits Error the characters are there
these to be exact 
First of thanks for your time tested code,
everything I have done works just as I needed it , however I have some unwanted encoding hexes that appear in the suggest box at the top , if you take a look at this bare bone example you will see it , weather it finds a hit in the DB or spits Error the characters are there
these to be exact 
http://www.episd.org/_departments/purchasing/ac/index.php
I should have read the comments, as I did what Jamie said and they went away , Jamie you are 100% accurate with the fix to those characters, NOTE: Dreamweaver cs4 will not show those characters in the source I did go into a cPanel and did see those characters in the source , problem fixed, thanks
Gorilla, I can’t find any previous posts from you, so I am not sure what you want to do.
If you want to search more than one column, and only have one drop down, you don’t need to change the variables, you need to change the SQL command in rpc.php
If you want multiple drop downs, you would need to change the javascript. And how to change it, would depend on what you were trying to do. More details about what you are looking for, please
Pete Clark:
Multiple drop downs, yes that would be great! An example could be, that you have separate categories –> Movies and actors.
If I type for example: s
Result would be that both drop downs would give me suggestions at the same time. The first drop down displays suggestions about “movies”, the second drop down about “actors”, all that start with the letter “s”.
Demo: prisjakt.se
Try the searchbox for this swedish site and type for example: “sony”. This would display “Products” suggestions in a box, “manufactures” in a another box, and even a third one.
How is this done? I would like to modify Jamies code.
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
Thanks for the reply Pete!
What I’m trying to do is have a text field dynamically generated for each column that I’d have in a table. For example, if a user wants to change a value in a column, when they try to modify it, it will suggest values already in that column so they don’t go about misspelling of unnecessarily adding other spelling variants. I believe post 45 by netziro is what I want, but I’m really weak on javascript and ajax (sitting with his o’reilly ‘learning javascript’ book out because his ‘definitive javascript’ book kicked his butt)…
I see netziro has posted his modified version of the functions used, but I’m not sure how to pass the parameters TO the function and the ‘tabella’ and ‘campos’ variables which I assume is his ‘table’ and ‘columns’…
Essentially…
is there a hidden value method of including my desired table name and column such that i could pass it into the lookup function where I can then post it to the rcp.php file where I can acquire it there via the post variable ie. $_POST['table'] and $_POST['column']
function lookup(inputString) {
if(inputString.length == 0) {
// Hide the suggestion box.
$(‘#suggestions’).hide();
} else {
$.post(“rpc.php”, {queryString: “”+inputString+”"},
I thought more about it… I suppose, I’m just not sure what’s the best way to pass the variables to the lookup function.
ie. should I use addition input fields where type=hidden
so then I can get function lookup(inputString, tableString, columnString) { … $.post(”rpc.php”, {queryString: “”+inputString+tableQueryString: “”+tableString””+columnQueryString: “”+columnString””}}
Thanks guys, I guess I was being thick. I looked more closely at netziro’s post, and I think this should do the trick…
$table = ‘mytable’;
$column = ‘mycolumn’;
”
function lookup(inputString) {
if(inputString.length == 0) {
// Hide the suggestion box.
$(‘#suggestions’).hide();
} else {
$.post(”rpc.php”, {queryString: “”+inputString+””, queryTableString: “”+tableString+”, queryColumnString: “”+columnString+”},
it’s not working YET but I think it’ll just require some diligence and patience on my part… thanks again chaps
whoops, it didn’t post,
input type=\”text\” name=\”update\” size=\”10\” id=\”inputString\” onkeyup=\”lookup(this.value, ‘$table’, ‘$table_title[$i]‘);\” onblur=\”fill();\”
and there should be additional arguments for my lookup–it works now–success!
i searched multiple db’s using a sql command like below – not to sure how fast it runs on a huge db with lots of info held within.
————————
$query = $db->query(”
SELECT “.TABLE__MMCL__ARTISTNAME.” FROM “.TABLE__MMCL.” WHERE “.TABLE__MMCL__ARTISTNAME.” LIKE ‘$queryString%’
UNION
SELECT “.TABLE__MMCL__PERFORMANCE.” FROM “.TABLE__MMCL.” WHERE “.TABLE__MMCL__PERFORMANCE.” LIKE ‘$queryString%’
UNION
SELECT “.TABLE__IMTL__ARTISTNAME.” FROM “.TABLE__IMTL.” WHERE “.TABLE__IMTL__ARTISTNAME.” LIKE ‘$queryString%’
UNION
SELECT “.TABLE__IMTL__PERFORMANCE.” FROM “.TABLE__IMTL.” WHERE “.TABLE__IMTL__PERFORMANCE.” LIKE ‘$queryString%’
UNION
SELECT “.TABLE__IMTL__INDIVIDUAL_TRACKNAME.” FROM “.TABLE__IMTL.” WHERE “.TABLE__IMTL__INDIVIDUAL_TRACKNAME.” LIKE ‘$queryString%’
UNION
SELECT “.TABLE__TSPL__ARTISTNAME.” FROM “.TABLE__TSPL.” WHERE “.TABLE__TSPL__ARTISTNAME.” LIKE ‘$queryString%’
UNION
SELECT “.TABLE__TSPL__TRACK.” FROM “.TABLE__TSPL.” WHERE “.TABLE__TSPL__TRACK.” LIKE ‘$queryString%’
UNION
SELECT “.TABLE__DMCL__EPISODE_NAME.” FROM “.TABLE__DMCL.” WHERE “.TABLE__DMCL__EPISODE_NAME.” LIKE ‘$queryString%’
UNION
SELECT “.TABLE__DMCL__SERIES.” FROM “.TABLE__DMCL.” WHERE “.TABLE__DMCL__SERIES.” LIKE ‘$queryString%’
LIMIT 0, 20″);
Hi Jamie,
I love this suggest box, it’s looking great. I’m just having one small problem getting it to work.
The line $(‘#inputString’).val(theString); in the fill() function seems to be causing the issue. I can’t get this to work in either google chrome or Opera. The error chrome gives me is a ReferenceError: fathert98 is not defined (fathert98 was my search string). The popup works, the issue is when I click on the value.
Hope you can help,
David.
Hi.. Can we send other data in the line:
$.post(“rpc.php”, {queryString: “”+x+”"}, function(data)….
i mean i need to send other var to rcp.php…
i u can help me let me know..
thanks 4 the code!!
you could change the post function to something like this:
$.post(“comment.php”,
{
video_id:$(“#video_id”).val() , user_id:$(“#user_id”).val() , fullname:$(“#fullname”).val() , videocomment:$(“#videocomment”).val(),
},
can’t get the value upon clicking on the suggested list
Hi,
Thank you for a good stuff…
Thank you
Charlie
Great tutorial — I hope everyone knows this was a tutorial, and not to just copy the code in production.
It works for me in ie7 but not in firefox. Would that be javascript or css?
@Sandeep – The example on this page works in all browsers for me. What are you experiencing that tells you it doesn’t work? The box just doesn’t pop up at all?
It sounds like a javascript issue — possibly an issue with the php though, do the database queries work if you test it with static values?
posy the error
Nice tuto, thanks a lot
i’ve fixed the z-index issue on FF using z-index:9999 !important
but still not working on IE7
Any idea ??
Thanks
Thanks Sean,
It seems to be javascript isssue. Because I don’t have good knowledge of javascript, is there any thing I can try with this script to get it working in firefox?
http://www.buildingmanager.com.au/test
Thanks for the script, it really usefull for me, but seems the js script being scramble ??
I have a non working version also @ once.
I get an error on the javascript but have not found out yet where it exists.
More people have this ?
@Matts
Which version ??
can you send me email at dev_hda1@linuxmail.org ?
[...] AutoCompleter Tutorial - jQuery(Ajax)/PHP/MySQL [...]
Wow. This is very cool. Thanks for your work on this.
Got it working….but….has anyone got arrow keys working for selecttion on this yet?!?!?! That would make useability so much better….. I know there are examples of this elsewhere but they give diddly-squat help whereas this page is very helpful with set-up…
I am still having issues with firefox. It’s giving me 403 forbidden error in firebug.
But it works fine in ie.
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
muy buenos tu tutorias pero puedo tene en mi mail sobres ajax script en mi mail sobres else if
http://www.vulgarisoip.com/
http://www.vulgarisoip.com/2007/08/06/jquerysuggest-11/
2 alternatives
HELP PLEASE!!!!
im running on php4, and have the div box populating with correct data out of my db, but i cant scroll through the list or pick anything so it populates the input box!!!!?!??!?! It just displays everything that starts with “ar…”
PLEASE SOMEONE HELP ME!!!
[...] Autocomplete by AjaxDaddy jQuery Autocomplete Plugin with HTML formatting jQuery Autocompleter AutoCompleter (Tutorial with PHP&MySQL) quick Search jQuery [...]
Basic but effective. I’ve changed the query method to GET for my own purposes, added dynamic positioning based on where the input field is located and assigned the onkeyup dynamically. The lattest is quite easy to do. Stick this where your script is:
$(document).ready(function() { $(“#inputString”).keyup(lookup(this.value)) } )
Also, a timer won’t hurt to only bring down the box after a little while. Use setTimeout()
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
[...] Autocomplete by AjaxDaddy. jQuery Autocomplete Plugin with HTML formatting. jQuery Autocompleter. AutoCompleter (Tutorial with PHP&MySQL). quick Search jQuery [...]
I would like to add this autocomplete script (countries) in multiple location in a form, do you know how to fix it?
Thanks
It would be nice with a “No results” if you enter something that’s not listed! Does anyone know if this is possible?
This should work, and also show “no result”:
<?php
include(‘db_connect.php’);
$query = mysql_query(“SELECT * FROM Movies WHERE $Title LIKE ‘$queryString%’ ORDER BY $Title asc LIMIT 10″);
$number=mysql_num_rows($query);
if ($number < 1)
{
echo “Sorry – no result.”;
}
else
{
while ($row = mysql_fetch_assoc($query) )
{
$Title = $row['Title'];
echo ”.$Title.”;
}
}
mysql_close();
?>
Hi,
You script works well, I have connected to my application. But I got a trouble that I don’t know how to solve it.
In fact as we show on you demo (http://res.nodstrum.com/autoComplete/index.htm) when entering some text, the small windows with choises appears. But the rest of the page is going down.
Is there any way to make the choises upon the rest of the page ?
Thanks for all
you could change your css to position:absolute; and possibly the z-index may work.
I got some improvments thanks.
You’re right, once it is set to absolute I can move with it by the CSS.
enjoy !!!
[...] AutoCompleter (Tutorial with PHP&MySQL). [...]
[...] Autocomplete – jQuery ajax [...]
Hello Jamie,
you did amazing work! i’m testing with some keyboard features, but still nothing works…
Did you manage it to make the up and down-arrows work within the suggestion list?
Greetings
John
Is there perhabs a possibility to use the jquery keynav-plugin? This would be the “total package”…
any suggestions?
greetings
John
Hi! this tut was gr8 but i am having the trouble with the onclick property coz when i click on the item on the suggestion box the item is not displeyed in the text box.
Is there something needed to be fixed in onblur.
regards
uday
someone emailed me about 2 columns being selected w/this demo … i deleted the email by accident. please email be back. my addy is higher up on this page. I HAVE SUCCESSFULLY QYERIED 2 COLUMNS AT ONCE. there is a small bug though, the results (query results) are sorted in an odd way. i had PRODUCT NAMES and PRODUCT #s in 2 columns.
$query = $db->query(“SELECT productName AS products FROM product UNION SELECT productNumber AS products FROM product WHERE productNumber LIKE ‘$queryString%’ or productName LIKE ‘$queryString%’ LIMIT 15″);
hi!
i am having the trouble with the onclick property coz when i click on the item on the suggestion box the item is not displeyed in the text box.
Is there something needed to be fixed in onblur.
CAN SOMEONE PLEASE HELP ME OUT ITS IMPORTANT.
regards
uday8486@gmail.com
hi!
i am having the trouble with the onclick property coz when i click on the item on the suggestion box the item is not displeyed in the text box.
Is there something needed to be fixed in onblur.
CAN SOMEONE PLEASE HELP ME OUT ITS IMPORTANT.
regards
uday8486@gmail.com
Hi,
Great script and tutorial! Has anyone modified the code to support multiple input fields?
Thanks,
Asher
i would be interested in seeing your code if you get it working :p
Great script, but, how does it deal with apostrophes and quotes? My data goes into mysql via PHP and I addslashes to strings with apostrophes or quotes. I have even changed them to " abd ' but it still will not work in this script. I know the problem is in the javascript–I need to escape the string–and I have tried that and it still does not work. It seems as long as the string has the apostrophe, the script will not work. Has anyone figured out how to deal with this? Try St. Valentine’s Day as a string and you will see what I mean. Many thanks in advance.
Is anyone aware of a way I can filter the results of the query so it doesn’t display duplicates?
For example, if the SQL query is searching a column called “name” and the input queryString is “bob”, if there is more than one entry for “bob” then it’ll suggest that name twice which is unnecessary.
Any help?
Just add DISTINCT to the query? so SELECT DISTINCT * from etc etc
i am having the trouble with the onclick property coz when i click on the item on the suggestion box the item is not displeyed in the text box.
Is there something needed to be fixed in onblur.
CAN SOMEONE PLEASE HELP ME OUT ITS IMPORTANT
I fould that a few people, including me are haveing dificulty with this script when it comes to calling up part of a mult-word result. United Kingdom for example was not being found on the search King…
A very simple fix for me was to change:
WHERE name LIKE ‘$queryString%’ to
WHERE name LIKE ‘%$queryString%’
Working perfectly now. Thanks for a great script!
Hi, I worked to try to solve my problem of quotes and apostrophes. I get it to work if when I upload my content to MySQL I change the apostrophe to \" –the first \ is necessary for the javascript. The only problem that I have, and it is a asmall problem, is that the \ sppears in the suggestion box. It does not appear when selected. Any suggestions?
[...] AutoCompleter Tutorial This tutorial produces a result similar to the preceding tutorial. [...]
Jamie,
Followed the tutorial very carefully and have the problem of it saying “There should be no direct access to this script!” There is an obvious reason for this error but not sure what it is and what I have done wrong.
Jennifer
Thanks for the jQuery script, nice and lightweight! Installed and working 100% in code igniter in 10 mins!
Thanks Again
Using with mouse only select the value. But not with key board and there should be a scroll bar feature like dropdown list
we’ll give it a try. Thank you
$value = str_ireplace($queryString, ” . $queryString . “”, $result->value);
Adds a class ‘found’ to the letters the script found in the result. Helps show the user where the result came from and adds more interaction to the script.
$value = str_ireplace($queryString, <span class="found"> . $queryString . </span>, $result->value);
Adds a class ‘found’ to the letters the script found in the result. Helps show the user where the result came from and adds more interaction to the script.
It would be even better if user can press “up” or “down” key from the keyboard to select records from the selection box!
plz help me for php4
plz help me for php4
There was someone above who had a solution to the suggest box staying active even when the input field is bogus
valllllllllllllllllllllllll
Has anyone ome up with a solution to this. Making
if(data.length >90) {
is not really a solution..
Perhaps it needs to retrieve the results of the query and if the count is 0 then ‘hide’ suggestion box???
nice very nice, I spent two day but finnaly got it runnig with smarty,.
I changed this
my index.php
search_now($queryString);
break;
}
?>
now my function:
function search_now($queryString)
{
if($queryString){
$resultv = “SELECT * FROM videocat WHERE nombre LIKE \”%$queryString%\” ORDER BY id DESC LIMIT 5″ ;
$resultv=mysql_query($resultv) or die (mysql_error());
$result=mysql_num_rows($resutv);
$i=0;
while ($row2 = mysql_fetch_array($resultv))
{
$res_id[$i] = $row2['id'];
$res_nombre[$i] = $row2['nombre'];
$res_imagen[$i] = $row2['imagen'];
$i++;
}
$this->tpl->assign(‘res_nombre’, $res_nombre);
$this->tpl->assign(‘res_imagen’, $res_imagen);
$this->tpl->assign(‘res_id’, $res_id);
$this->tpl->display(‘resultadosb.tpl’);
}
else
{
$this->tpl->display(‘error.tpl’);
}
}
now my resultadosb.tpl:
{section name=”i” loop=”$res_id”}
{thumb file=”imagenes/$res_imagen[i]” width=”30″ height=”30″ link=”false”;}
{$res_nombre[i]}
{/section}
and finnaly my calls thisi named buscame.tpl whis is the file i include in every tpl i wanted the form it display my link my image and works like charm. :
Ajax Auto Suggest
{literal}
function lookup(inputString) {
if(inputString.length == 0) {
// Hide the suggestion box.
$(‘#suggestions’).hide();
} else {
$.post(“buscara.php”, {queryString: “”+inputString+”"}, function(data){
if(data.length >0) {
$(‘#suggestions’).show();
$(‘#autoSuggestionsList’).html(data);
}
});
}
} // lookup
function fill(thisValue) {
$(‘#inputString’).val(thisValue);
setTimeout(“$(‘#suggestions’).hide();”, 200);
}
{/literal}
Buscar Artista/Banda:
Hi,
I got solution for special characters
like í … áéíóúÁÉÍÓÚ
-> for latin symbols
This is my code in script PHP:
while(….){
$readvalue= htmlentities($result->values, ENT_QUOTES, ‘Windows-1252′); // new line!
echo ”.$readvalue.”;
}
Hi, this is a great script…
I would like to request several fields to mysql and with the returned values i would like to fill a form with those fields…
How to do that?
Thanks
Hello, I have used this script, but it doesn work without mysqli extension, the problem was I didn’t have mysqli and I had to modify the PHP script using my own classes to do it work.
My question is; what type of licence your script have?, may I modify, distribute and use it in any place I want?
Saludos desde México
Armando
Sorry, i have found my answer:
“MIT License”
Gracias
[...] habs selber gefunden. Ich habe es mit folgender Anleitung gemacht: AutoCompleter Tutorial – jQuery(Ajax)/PHP/MySQL – Nodstrum Trotzdem Danke an [...]
hi jamie,
does this work on IE-6 AND ONWARDS.
i am receiving certain problems . i have updated the script for my own purpose this way.take a look and suggest a change of what really went wrong.
my code :
0)
{
$sql = “SELECT * FROM countries WHERE value LIKE ‘i%’”;
$query = mysql_query($sql);
while ($result = mysql_fetch_array($query))
{
echo “”.$result['value'].”";
}
}
}
?>
pleas etake a look at my code and suggest me what went wrong.
i modifies the script this way to fill in my purpose.
0)
{
$sql = “SELECT * FROM countries WHERE value LIKE ‘i%’”;
$query = mysql_query($sql);
while ($result = mysql_fetch_array($query))
{
echo “”.$result['value'].”";
}
}
}
?>
i am getting error with this code.please suggest the way out.does it work in IE-6 and onwards?
0)
{
$sql = “SELECT * FROM countries WHERE value LIKE ‘i%’”;
$query = mysql_query($sql);
while ($result = mysql_fetch_array($query))
{
echo “”.$result['value'].”";
}
}
}
?>
Hi shibasisn,
this is my complete code:
if($query) {
// While there are results loop through them – fetching an Object (i like PHP5 btw!).
while ($result = $query ->fetch_object()) {
// Format the results, im using for the list, you can change it.
// The onClick function fills the textbox with the result.
// YOU MUST CHANGE: $result->value to $result->your_colum
$writeout= htmlentities($result->value, ENT_QUOTES, ‘Windows-1252′); // ok!!!
echo ”.$writeout.”;
}
}
Good luck!
The solution for PHP4:
/* MYSQL_BOTH :Columns are returned into the array
having both a numerical index and
the fieldname as the array index.
*/
$query = mysql_query(“SELECT value FROM countries WHERE value LIKE ‘$queryString%’ LIMIT 10″);
if($query) {
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
$writeout= htmlentities($row["value"], ENT_QUOTES, ‘Windows-1252′); // ok!!!
echo ”.$writeout.”;
}
}
Good luck!
ahh! on submit not display ok
like …
For PHP4:
/* MYSQL_BOTH :Columns are returned into the array
having both a numerical index and
the fieldname as the array index.
*/
$query = mysql_query(“SELECT value FROM countries WHERE value LIKE ‘$queryString%’ LIMIT 10″);
if($query) {
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
$writeout= htmlentities($row["value"], ENT_QUOTES, ‘Windows-1252′); // ok!!!
echo “”.$writeout.”";
}
}
I try again …
command echo not display ok in this post …
e.,c.,h.,o., “”.$writeout.”";
Very cool. Can’t wait to try it out!
i am using a php page and it is not index page either.. so do i need to make changes in ‘$(‘#autoSuggestionsList’).html(data);’
plz help..
Hello! I’m french (sorry for my english)
I want to use your script but it doesn’t works… database error on the “rpc.php”
I try to follow your previous comment ” March 19th, 2009 at 3:37 am ” but i don’t know how to put it ?
Please, could you explain or give all code “rpc.php” file ?
Thank you.
Good day
the script is almost what I need!!
I need to get both the name of the country and it