Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #22072

Re: Syntax to access the selected option's value

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.datemas.de!uucp.gnuu.de!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail
Content-Type text/plain; charset="UTF-8"
Message-ID <1930014.TA4aT0qaH3@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Reply-To Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Organization PointedEars Software (PES)
Date Tue, 19 Nov 2013 19:55:15 +0100
User-Agent KNode/4.10.5
Content-Transfer-Encoding 8Bit
X-Face %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v
Face iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg==
Subject Re: Syntax to access the selected option's value
Newsgroups comp.lang.javascript
References <7fc7ae95-94ad-4c65-9596-3a63d245360e@googlegroups.com> <528b9f28$0$9502$9b4e6d93@newsspool1.arcor-online.net>
MIME-Version 1.0
Lines 43
NNTP-Posting-Date 19 Nov 2013 19:55:28 CET
NNTP-Posting-Host 6caa75c1.newsspool1.arcor-online.net
X-Trace DXC=VT6h>hiML>7TQL:hoD@>T?ic==]BZ:af>4Fo<]lROoR1nkgeX?EC@@0\BGGOn[Md>8DZm8W4\YJN<YUVHKH;GI^739Y];>:8@l47Y;\C?FaA75
X-Complaints-To usenet-abuse@arcor.de
Xref csiph.com comp.lang.javascript:22072

Show key headers only | View raw


Christoph Michael Becker wrote:

> Bart Van der Donck wrote:
>> Say the following code:
>> 
>> <form name="f" method="get"> <select name="myName" id="myID"> <option
>> value="a">a</option> <option value="b">b</option> <option
>> value="c">c</option> </select> </form>
>> 
>> There are two 'official' ways to read out the current selected
>> value:
>> 
>> document.getElementById('myID').value
>> document.f.myName.options[document.f.myName.selectedIndex].value
> 
> It seems reasonable to distinguish between referencing the form element
> and accessing its value.  The latter is explained in this NG's FAQ[1],
> the former in a side note to the FAQ[2].

However, the “official“, i.e. *both* standards-compliant and backwards-
compatible approach is

  var el = document.form["f"].elements["myName"];
  el.options[el.selectedIndex].value

but it only works for el.type == "select-one", and it is necessary to check 
that el.selectedIndex is not out of bounds; at least, that it is not 
negative.

>> But I can't find any reasonable environment where the following
>> fails:
>> 
>> document.f.myName.value
> 
> As explained in the FAQ[1], this would fail under NN4, for instance.

It also fails under certain circumstances in IE/MSHTML.
 
-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Syntax to access the selected option's value Bart Van der Donck <bart@nijlen.com> - 2013-11-19 06:20 -0800
  Re: Syntax to access the selected option's value "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-11-19 08:27 -0800
  Re: Syntax to access the selected option's value Christoph Michael Becker <cmbecker69@arcor.de> - 2013-11-19 18:26 +0100
    Re: Syntax to access the selected option's value Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-19 19:55 +0100
      Re: Syntax to access the selected option's value Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-19 19:18 +0000
        Re: Syntax to access the selected option's value Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-19 22:48 +0100
  Re: Syntax to access the selected option's value "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2013-11-19 19:32 +0200
    Re: Syntax to access the selected option's value Bart Van der Donck <bart@nijlen.com> - 2013-11-20 02:40 -0800
      Re: Syntax to access the selected option's value Christoph Michael Becker <cmbecker69@arcor.de> - 2013-11-21 22:27 +0100

csiph-web