Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A hackish solution</p> <p>[Edited solution]</p> <pre><code>var clickDown = false; var currentlySelected = null; $("#ListBox").mousedown(function (event) { clickDown = this; }); $(document).mouseup(function () { setTimeout(function() { if (clickDown) { if (currentlySelected != clickDown.selectedIndex) { alert("change"); currentlySelected = clickDown.selectedIndex; } clickDown = false; } }, 0); }); </code></pre> <p>Basically on mouseDown we set a flag saying you click on the listbox.</p> <p>Then we check <em>every</em> mouseUp in the entire document. We wrap the entire function in a timeout to ensure that <em>IE8</em> sets the selectedIndex correctly. And if the clickDown flag is set we know that the clickUp came from a listbox. For convience I also store the listbox object in the flag since (object === true) in javascript.</p> <p>Then we simply check if our variable containing the current index has changed. If so a change occurs and we update that variable to reflect the new index.</p> <p>Finally we have to set clickDown to false again outer wise other click ups in the document would think there from the listbox.</p> <p>This involves checking every click up and is by no means an <em>elegant</em> solution</p> <p><a href="http://jsfiddle.net/as7EN/37/" rel="nofollow">http://jsfiddle.net/as7EN/37/</a></p> <p>[Edit] That only fixed it for chrome. Not for IE8. Working on it.</p> <p>I've narrowed it down to the fact that IE changes the selectedIndex after the mouseUp event is triggered.</p> <p>This bug can be avoided by wrapping it in a timeOut so that the function gets called after IE8 sets selectedIndex to the real value. I dont care about IE6/7 fix that yourself.</p> <p>Also if you want multiselect to work tell me and I'll hack that around aswell</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload