...

View Full Version : event capture on autocomplete dropdowns



martin_narg
01-20-2006, 05:15 PM
Hey guys,

Does anyone know how to event capture on an autocomplete dropdown - this would not be the underlying html element but only on the autocomplete dropdown itself.

I've never come across trying to capture autocompletes before (in fact, ideally i'm trying to ignore keypresses on the autocomplete and only capture those for the underlying input).

Many thanks for your time and consideration.

m_n

GJay
01-20-2006, 07:21 PM
Some code would be useful, 'autocomplete dropdown' could be implemented in a number of ways...

brothercake
01-20-2006, 08:01 PM
You mean when autocomplete fills in a form field? If so, Firefox should fire the onchange event, and I think IE fires the onpropertychange event. Don't think there's anything for Opera or Safari.

martin_narg
01-22-2006, 08:46 AM
hey guys

the problem i'm facing is that i have a login form that doesn't have a submit button and hence when a user hits the enter key the form doesn't submit as it natively would do - it's necessary to capture the keypress, check if it's the enter key and submit the form. A simplified version would look like this:
function checkSubmit(e) {
if(e.keyCode == 13) {
(e.target || e.srcElement).form.submit();
}
}
html:
<input type="text" name="username" onkeyup="checkSubmit(event);">
The trouble is that if the user has their browser autocomplete turned on and then they select their username from the dropdown, when they hit enter to select their username from the autocomplete list, the keypress is actually fired on the underlying input element (due to event handling being part of the DOM, and not part of the browser functionality). So I'm apecifically looking to check to see if the user has hit enter to select an autocomplete option. As i mentioned, as autocomplete is not part of the DOM then this is not as simple as it first appears.

Brothercake:
Yeah, I've now looked at something similar combining onkeydown and onkeyup to check the previous value against the new value and submitting if necessary. I was hoping for a more elegant solution though using a single event object. Perhaps it's not possible - it seems logical not to be able to capture inbuilt browser functionality when it goes against the various DOM specs, but would be elegant to have all user interaction available to be totally capturable.

Many thanks for your responses, anything further is greatly appreciated.

m_n

liorean
01-22-2006, 09:14 AM
Well, I cannot give you an answer, but these sound like they could possibly be of interest:

<uri:http://www.w3.org/TR/DOM-Level-3-Events/events.html#event-textInput>
<uri:http://www.w3.org/TR/DOM-Level-3-Events/events.html#event-DOMActivate>
<uri:http://whatwg.org/specs/web-forms/current-work/#the-change>

martin_narg
01-23-2006, 10:15 AM
Very helpful liorean, excellent.

Many thanks to yourself and all others who responded.

m_n



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum