[thelist] Deselecting a select element in JS

Hardacker, Andrew Andrew.Hardacker at Compuware.com
Thu Mar 21 14:56:01 CST 2002


jeff, thanks for your well-considered reply. I hate to fan this up again but
I'd like to clarify a couple of points.

This W3 document, ECMA Script Language Binding, does specify that
selectedIndex is long (which, in most languages, is a signed integer capable
of holding a positive or negative value). There is no mention of valid
range; I made my assumption solely on Goodman's statement. And we know what
happens when we assume...

http://www.w3.org/TR/2000/PR-DOM-Level-2-HTML-20000927/ecma-script-binding.h
tml

<snip>
when the word netscape is used, i automatically think nn4.  want me to think
nn6?
</snip>
Yes, sorry, Netscape6. At work (where I am allegedly doing productive work
even at this minute), our "lowest common denominator" for browsers is IE5.0
and Netscape6.2. (I forced Netscape6.1 out of the requirements.) Netscape6
may very well have a bug; without strong documentation on how this is
supposed to work, we may never know how it's supposed to work, although we
probably agree on how it _should_ work.

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> This works in Netscape6, but not IE. What's wrong?
>
> function deselect() {
>  var s = document.getElementById('s');
>  alert("before: selected="+s.selectedIndex);
>  for (var i=0;i < s.length; i++) {
>   s.options[i].selected = false;
>  }
>  alert("after: selected="+s.selectedIndex);
> }
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
This bit of code was just a response to your original suggestion to loop
through the selected attributes.

<snip>
fwiw, i don't see any point in referencing form elements via
getElementyById() as this unnecessarily breaks form interaction for older
browsers
</snip>
Again, this was merely a test, not something I was coding for production,
only an effort to answer Olly's original question.

<snip>
don't go just yet.
</snip>
OK, but I should get back to work on my applet. btw, during this testing
Homesite5 crashed. Again. I've been using Homesite since its 1.x/$25
shareware days and I'm quite attached to it, but I would never call it
stable. A crash a day, even with version 5.

Andy Hardacker
http://hardacker.com/



The contents of this e-mail are intended for the named addressee only. It
contains information that may be confidential. Unless you are the named
addressee or an authorized designee, you may not copy or use it, or disclose
it to anyone else. If you received it in error please notify us immediately
and then destroy it.




More information about the thelist mailing list