Recently I published an updated version of my auto-complete (Google suggest) script compatible with IE and FireFox and based on PHP/AJAX.
After publishing version 1.0, I had some feedback from people who downloaded an tested it, so now I decided to correct some of the bugs that were found, and make a few improvements also. So now I’m going to publish version 1.1, check out some of the changes I made.
FIX: Pressing TAB/ENTER with nothing selected returned an error message
Always when TAB/ENTER was pressed without any list item selected an error message was returned because the script couldn’t find the value it expected to find, this issue was resolved by adding a flag that made the script ignore this command in this case, causing it to just hide the div.
if (me.highlighted.id != undefined){ me.acChoose(me.highlighted.id); }
CSS: FireFox showed no linebreaks
Who tried out my script in FireFox noticed that sometimes the list appeared on a single line, with no line breaks between the items, a simple change in the CSS style of the LI element resolved the problem
#acDiv UL LI{ display:block;}
FEATURE: Adding multiple auto-completes in a single page
Due to the way I was referencing the AC object in the script it was impossible to change the name of the variable that received the object. So adding more than one was an impossible mission. Adapting the reference I made it possible to add multiple scripts, as in the example:
var AC = new dmsAutoComplete('string','acDiv'); AC.chooseFunc = function(id,label){ alert(id+'-'+label); } var AC2 = new dmsAutoComplete('string2','acDiv2'); AC2.chooseFunc = function(id,label){ alert(id+'-'+label); }
Version 1.1 of the script is available in the same link as before:
If you would like to know more about the scripts history look here
If you happen to find the script useful and decide to use it in your solution please let me know, give me some feedback on the bugs, and let me know how it worked for you.
This post is also available in: Portuguese (Brazil)
dmsAutoComplete v1.1 – ChangeLog
short out this error…
using Mozilla firefox
Error: uncaught exception: [Exception… “Component returned failure code: 0x804b000f [nsIXMLHttpRequest.setRequestHeader]” nsresult: “0x804b000f ()” location: “JS frame :: http://blog.rafaeldohms.com.br/myprojects/autocomplete/dmsAutoComplete.js :: anonymous :: line 187″ data: no]
Ao pressionar as teclas UP/DOWN sem ter iniciado a busca, ocorrem vários erros no javascript.
I love your script, but I cannot get it to work on my site. I don’t get any error messages, but the drop-down box never gets populated with any items. The example on your site works fine for me. I am using PHP 5, and I’ve set permissions for your files to 755. Any thoughts on what I might try? My example page is here:
http://scripts.mit.edu/~jonb/dmsAutoComplete/example.htm
Thanks!
OK, I was able to get your script to work on a different server, but I really need to get it to work on my own. My server is running PHP Version 5.1.6, while the server on which I got it to work is running Version 5.2.1-0.dotdeb.2. Should this make a difference as to whether your script will work? Are there any other environmental variables I should be checking?
The Script is working fine.I am getting small problem when ever i type drop down is coming but All the select boxes in that page disappearing after selecting one option again select box are visible again. Please let me know how to avoid this
Thanks
Muktha
Sobha,
That’s right, this happens because in some browsers the auto-complete div cannot stay on top of the slect boxes, so i hide them all and return them afterwards.
There is a true/false flag to disable this behaviour, just add this line to the script invocation:
AC.hideSelects = false;
That should stop that behaviour, but beware if you have any select below the auto-complete div, for thei will stay over the div in som browsers.
Cheers!