Auto-complete text boxes
There’s a great new article up on Sitepoint describing a technique for adding auto-complete functionality to normal HTML text input fields using Javascript. The code uses a whole bunch of browser-specific code, but it has to thanks to the unconsistent ways in which different browsers handle text selection ranges. Unfortunately the article doesn’t actually provide a demo of the code in action, so I’ve posted one here. It’s a very nice effect.
Tony Bowden - 20th September 2003 11:42 - #
WFM in Mozilla Firebird 0.6.1+. It didn't work at first because I had set my user agent string to IE 6.0 WinXP. The script uses browser detection instead of object detection, which is not The Right Way™ to do it.
Nice script, though. I was thinking of doing this myself, but I never got around to actually implementing it.
Jan! - 20th September 2003 12:01 - #
document.selection.createRangeobject used by IE).Simon Willison - 20th September 2003 12:24 - #
Scott Hanson - 20th September 2003 15:07 - #
Dylan Moreland - 20th September 2003 17:09 - #
Thijs van der Vossen - 20th September 2003 18:06 - #
broken in IE/Mac...
Eric Scheid - 21st September 2003 06:49 - #
Additionally, in Opera 7.20 I have no keyboard response.
Thomas Scholz - 21st September 2003 07:14 - #
Manu - 21st September 2003 19:31 - #
James 'Smiler' Farrer - 22nd September 2003 11:42 - #
Andrew Wooldridge - 22nd September 2003 21:04 - #
- Mozilla 1.4 / Win2K
- Mozilla 1.5 (RC1) / Win2K
- IE 5.5 / Win2K
- IE 6 / Win2K
- Firebird 0.6.1 / Mac OS X 10.2 Does not work, but does not break
- Mac IE 5.2 / Mac OS X 10.2 Does not work / page is broken
- Safari / Mac OS X 10.2
- Netscape 4.77 / Mac OS X 10.2 (OS 9)
Chris Heller - 29th September 2003 23:27 - #
levin - 2nd October 2003 00:47 - #
PIPPIRI VENU - 7th March 2006 05:07 - #
Re: "The biggest problem is that it breaks CTRL-A, CTRL-V, CTRL-C, etc." you can restore this functionality thus:
add the trap function (at bottom) to the script, then wrap the main autocomplete function in
function autocomplete(oTextbox, oEvent, arrValues) {
if (trap(oEvent) == true)
{}
else
{
switch ...snip.../snip...
}
function trap(e) {
if (!e) {
e = event;
e.which = e.keyCode;
}
try
{
modifierKey = e.ctrlKey || e.altKey || e.metaKey;
}
catch(e)
{
modifierKey = false;
}
//alert(modifierKey)
return modifierKey || e.which == 0;
}
David - 8th September 2006 14:10 - #