How To Close Combobox When Onmouseout? August 27, 2023 Post a Comment How to close combobox when onmouseout? VolvoSaabSolution 1: 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:selectEl.blur(); CopyAlthough, 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. Solution 2: You can do a little trick like this...<selectonmouseover="size = 5"onmouseout="size = 0"><optionvalue="volvo">Volvo</option><optionvalue="saab">Saab</option><optionvalue="mercedes">Mercedes</option><optionvalue="audi">Audi</option></select>CopyThis 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.Solution 3: 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.<scripttype="text/javascript">functionclickSelect(element) { var event = document.createEvent('MouseEvents'); event.initMouseEvent('mousedown', true, true); element.dispatchEvent(event); }; functiontoggleSelect() { clickSelect(document.getElementById("select")); } </script><form><selectid="select"><option>one</option><option>two</option></select><inputtype="button"onmouseover="toggleSelect();"value="toggle select state" /></form>Copy Share Post a Comment for "How To Close Combobox When Onmouseout?"
Post a Comment for "How To Close Combobox When Onmouseout?"