473,503 Members | 1,656 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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


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
2 2039
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
10031
by: Craig Keightley | last post by:
I have the following form <FORM NAME="form1" METHOD="POST"> <?php do { ?> <input name="approve" type="checkbox" id="approve" value="<?php echo $row_rs; ?>"> <select name="select"> <option...
0
2544
by: Kingdom | last post by:
I Need some serious help here. strugling novis with ASP and javascript any help would be greatly appreciated The script below does exactly what I want it to do for each product on the two passes...
5
3454
by: Nick Calladine | last post by:
Learning : Loop to list all dropdown box values on a form Can some one point me in the right direction : I have a form which I want to loop through I basically want to get all the selected...
24
40040
by: Nudge | last post by:
I have an array, and an unrolled loop which looks like this: do_something(A); do_something(A); .... do_something(A); I thought: why should I type so much? I should write a macro. So I was...
3
1352
by: Rudy | last post by:
I am writing a program in VB.NET and as I was debugging a problem I noticed my For loop doesn't want to loop! I originally had a upper bound which was an expression and it wasn't working. WHen I...
0
4078
by: tania | last post by:
i have this table in my database: CREATE TABLE FILM( F_ID INT(5) NOT NULL AUTO_INCREMENT, F_TITLE VARCHAR(40) NOT NULL, DIRECTOR_FNAME VARCHAR(20) NOT NULL, DIRECTOR_LNAME VARCHAR(20) NOT NULL,...
1
2433
by: Doug_J_W | last post by:
I have a Visual Basic (2005) project that contains around twenty embedded text files as resources. The text files contain two columns of real numbers that are separated by tab deliminator, and are...
5
2551
by: Richard Maher | last post by:
Hi, Can someone please show me how to tell Firefox to preseve white-space when returning the selectList.option.value attribute? I have change the style so that the white-space is preserved on...
3
1159
by: Cainnech | last post by:
Hi, I'm making a script where I need a for loop to get the values out of selects and do a function on it. Except I don't know how to get those values out if there because the id of the selects are...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7328
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7458
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.