How to close combobox when onmouseout?
<select onmouseout=""> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="mercedes">Mercedes</option> <option value="audi">Audi</option> </select>
You can't do this (reliably). The popup that appears is not available to manipulate, ie open or close, programmatically and its behaviour is defined by the browser (or operating system).
To expand on this further, both IE and Firefox can close the popup by blurring the select element:
Although, the mouseout event fires even when you move the mouse to the options in the popup, so it would require a bit of hackery magic. In Chrome it will blur the select element but the box will remain open.
It's generally best to leave the behaviour of UI components alone, so that users get the experience they expect through interaction with your website.
You can do a little trick like this...
<select onmouseover="size = 5" onmouseout="size = 0"> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="mercedes">Mercedes</option> <option value="audi">Audi</option> </select>
This will expand the menu on mouse over then collapse it when you move out.
Edit: This can cause issues with placement of other elements if you're not careful.
A couple of years late but in case someone else is looking at this...I was able to toggle the open/close state of a select element in Chrome by sending it a mouse click. In this example moving the mouse over the toggle button will toggle the state of the
<select>. This is a toggle, not an explicit open or close, but worked for me.
©2020 All rights reserved.