473,568 Members | 2,795 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.o ptions is an array
of objects and should be able to use this...

function methodTapeCheck (frm)
{
oddTT = frm.elements["oddTapeTyp e"];
alert("looping with explicit index");
for (x=0; x<oddTT.options .length; x++)
{
alert(oddTT.opt ions[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 2054
In article <MP************ ************@nn tp.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******@NOSPA M.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.o ptions 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
HTMLOptionsColl ection (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.opt ions[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/rasterTriangleD OM.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
10035
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 value="1">option 1</option> <option value="2">option 2</option> <option value="3">option 3</option>
0
2549
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 it makes however I would like the entire script to loop 34 times and on each of those 30 loops also write the product and the price (only) onto the...
5
3457
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 values of the option tag see example below
24
40102
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 looking to write something along the lines of:
3
1357
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 noticed this I changed the upper bound for a simple digit. As I step through my code, I see that it simply goes through the loop once and continues on...
0
4087
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, TYPE VARCHAR(30) NOT NULL, DURATION TIME , YEAR_RELEASE YEAR NOT NULL, DESCRIPTION TEXT,
1
2437
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 of different lengths (e.g. usually between 25 and 45 rows. The columns in each file have the same length). The text files have been numbered...
5
2557
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 the screen, but for some bizarre reason when I try to substring out a series of bytes (aka a fixed-length string or field) from a given option it...
3
1160
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 all different. Here's a piece of the code. <td> <select name="team1"> <option value="1">1</option>
0
7693
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7660
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7962
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6275
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5498
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.