views:

149

answers:

2

Is it possible to get event data from an HTML drop down list (i.e. the list that drops down, when you click on a drop down list) using jQuery / plain jscript? I am looking to capture:

  1. the number of times a user hovers over <option> before selecting the item they require.
  2. the duration of the hover before making a selection.

At present, the events i am able to capture are for the dropdownlist element itself not the list that drops down once it is clicked upon.

+1  A: 
<select id="test">
    <option value="1">one</option>
    <option value="2">two</option>
    <option value="3">three</option>
    <option value="4">four</option>
    <option value="5">five</option>
</select>

$(function(){
    $("#test option").mouseover(function(){
     console.log($(this).val());
    })
})

Works for me. You should be able to extrapolate from that to add some timers and counters to the mouseover/hover event to capture the data you want.

micmcg
I don't think you will get mouseover/mouseout events on options in IE or WebKit (Safari, Chrome), so this solution is not cross-browser.
Tim Down
+1  A: 

Of the mainstream browsers only Firefox supports mouseover/mouseout events on options so you should probably abandon the first part.

As to the second part, you may be able to do something with starting a timer when the <select>'s focus event fires and stopping it when the change event fires, though the focus event is not precisely what you're after. I don't think there is an event that fires when the <select> is expanded.

Tim Down
For the first part, as this is for a research project, using Firefox is fine. For the second part the focus event is adequate as i am looking to time users from when they focus on an element (be it by selecting an item or tabbing to it). Thanks for the responses!
Carl_Platt