By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,569 Members | 1,181 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,569 IT Pros & Developers. It's quick & easy.

for...in loop kills IE6 and doesn't get option values in NN6

P: n/a

Okay, trying to get the for...in loop syntax and obviously doing
something wrong.
I have a form and a select with options.
The explicit indexing I usually use works fine and alerts all the
values.
The for...in loop gives undefined for both IE and NN, but for IE, kills
it with way too many alerts. NN6 gives the right number of alerts (5
options, 5 alerts) but all say undefined.

Anyone know what I did wrong? AFAIK, selectElement.options is an array
of objects and should be able to use this...

function methodTapeCheck(frm)
{
oddTT = frm.elements["oddTapeType"];
alert("looping with explicit index");
for (x=0; x<oddTT.options.length; x++)
{
alert(oddTT.options[x].value); // alerts values correctly
}
alert("looping with for...in");
for (var o in oddTT.options)
{
alert(o.value); // alerts "undefined" for all; kills IE6
}
}
TIA

--
~kaeli~
Bakers trade bread recipes on a knead-to-know basis.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
In article <MP************************@nntp.lucent.com>,
ti******@NOSPAM.comcast.net enlightened us with...

Never mind. Lasse's reply to my other thread enlightened me as to why
this happened.

--
~kaeli~
A chicken crossing the road is poultry in motion.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #2

P: n/a
kaeli <ti******@NOSPAM.comcast.net> writes:
The for...in loop gives undefined for both IE and NN, but for IE, kills
it with way too many alerts. NN6 gives the right number of alerts (5
options, 5 alerts) but all say undefined.
The value of the variable is the *name* of the property, not the
property itself.
Anyone know what I did wrong? AFAIK, selectElement.options is an array
of objects and should be able to use this...
(Continuing another thread ... no, it is not an array (as in "an
instance created from the Array constructor"). It is an
HTMLOptionsCollection (see
<URL:http://www.w3.org/TR/DOM-Level-2-HTML/ecma-script-binding.html>).
It has a length property and an item method, but it lacks most other
characteristics of an actual array.)
for (var o in oddTT.options)
{
alert(o.value); // alerts "undefined" for all; kills IE6


Use:
alert(oddTT.options[o].value);

Try just:
alert(o)
to see what property names IE finds.

As I posted earlier, DOM nodes are not very good with for(in)-loops,
since there is no standard for which properties are enumerated and which
are not.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.