Re: Scrolling multiple-select, IE vs Firefox
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: Scrolling multiple-select, IE vs Firefox

From: Csaba Gabor <danswer@gmail.com>
Date: Mon May 01 2006 - 01:19:34 CEST

Alena wrote:
> Csaba, please, give me some additional information about the
> function(sel){return function() {
> sel.options[sel.options.length - 1].selected=true;}}(sel)
> How does it work?

Please read the three posts (5-7) starting from Richard Cornford's at:
http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/94165d8695faf91d/
and a bit of followup at (the last three posts. 6-8, of):
http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/bff638ebc5a4fe21/

In a nutshell, the code of the OP (original poster) mostly did what he
wanted, but when you modify form elements, especially when you are in
their event handlers, the modification might not be immediate (so any
follow on usage should wait a bit), or it might be immediate, but then
subsequent event handling (including default handling) might change it,
so the change should be postponed. In both cases, a window.setTimeout
will usually accomplish the waiting.

window.setTimeout can take a string as the first argument for what to
do, but it's much more cool to use a function instead. When
.setTimeout gets around to invoking the function, it doesn't pass any
arguments (mostly. See part 2 of the second thread for an exception),
but sometimes it is convenient for that function to know about values
that existed when the .setTimeout was called. That's why the inner
function (which is returned as the 1st argument to .setTimeout because
the outer function is evaluated) is wrapped in the outer one - the
inner function will know about the variables that are defined for the
outer function. So all I did was to put the OP's line of code in a(n
inner) function (so that .setTimeout could work with it), but I needed
to wrap that function in an outer function so the that the inner
function would know about the select element, sel, when it ran.
Received on Mon May 1 05:28:30 2006