简体   繁体   中英

Javascript autocomplete works in IE and Chrome, doesn't work in Firefox

I'm working on a client's site which utilizes a Javascript autocomplete feature in the search form. The website is in Hebrew, but please don't let that scare you away - my issue is in code, not English. :)
Link: -removed by author-
Most of the autocompletion options are in Hebrew but I added "test" so that it will be easy to test in English as well.
Basically this autocomplete script generates a text input box, and when the user types in a letter ( onkeyup ), a list of common values are offered (eg "test"). This works fine in both Chrome and IE, but for some reason Firefox is behaving differently.
When you enter a letter in Firefox, according to the error console:

Error: searchResult1 is not defined
Source File: 
Line: 1

Same goes for searchResult0 in the second input field (line ~460 in the source code).
If you look at -removed- the autocomplete script does work in Firefox, so I don't really know what it is I could have changed that broke its functionality.

Thank you for any help with this:)

The problem is onkeyup="searchResult1.style.visibility='visible';..." , it should be document.getElementById('searchResult1').style.visibility - you are referring to an element by its ID. It's an old MSIE feature that elements with an ID turn into "global variables" but that's really not something you should use. Other browsers implemented support for this misfeature ("global scope pollution") to stay compatible with MSIE but it is merely a compatibility layer and only kicks in under certain conditions.

Why don't you try using jquery autocomplete plugin rather than writing something on your own. The javascript written is not proper.

Its best to use the jquery autocomplete plugin. I see in you code you are jquery1.5.2

Autocomplete Demo: http://view.jquery.com/trunk/plugins/autocomplete/demo/

Download and documentation http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM