473,461 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

An element named 'length'

Hello, I'm having problems on IE 6.0 for Win XP. I want to iterate
through the elements of a form, but one of those elements is named
'length'. So, this JS code doesn't display any alert boxes, even
though it should display 3.

for (var i=0; i<myForm.elements.length; i++) {
alert(myForm.elements[i].name);
}

Can anyone suggest a cross-browser work-around? Thanks -
Jul 20 '05 #1
8 1310
On 2 Feb 2004 10:32:29 -0800, D. Alvarado <la***********@zipmail.com>
wrote:
Hello, I'm having problems on IE 6.0 for Win XP. I want to iterate
through the elements of a form, but one of those elements is named
'length'. So, this JS code doesn't display any alert boxes, even
though it should display 3.

for (var i=0; i<myForm.elements.length; i++) {
alert(myForm.elements[i].name);
}

Can anyone suggest a cross-browser work-around? Thanks -


Use FormObject.length instead.

In future, don't use names that might conflict with object properties and
methods.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #2
D. Alvarado wrote:
Hello, I'm having problems on IE 6.0 for Win XP. I want to iterate
through the elements of a form, but one of those elements is named
'length'. So, this JS code doesn't display any alert boxes, even
though it should display 3.

for (var i=0; i<myForm.elements.length; i++) {
alert(myForm.elements[i].name);
}

Can anyone suggest a cross-browser work-around? Thanks -


Hmmmm...

Option #1:
Rename the offending element to something else (such as len)

Opeiont #2:

for(var i in myForm.elements)
{
alert(myForm.elements[i].name);
}

Brian

Jul 20 '05 #3
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:op**************@news-text.blueyonder.co.uk...
<snip>
Use FormObject.length instead.
That probably won't help as providing the shortcut notation of allowing
named form controls to be accessed as named members of the form object
will mean that the - length - property of the form will have been
replaced with a reference to the same form control.

On DOM browsers:-

var inputs = formObject.getElementsByTagName('input');
var selects = formObject.getElementsByTagName('select');

- and iterating over the resulting nodeList objects. But there has got
to be a better way.
In future, don't use names that might conflict with
object properties and methods.


And that is it. :)

Richard.
Jul 20 '05 #4
On Mon, 2 Feb 2004 19:10:32 -0000, Richard Cornford
<Ri*****@litotes.demon.co.uk> wrote:
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:op**************@news-text.blueyonder.co.uk...
Use FormObject.length instead.


That probably won't help as providing the shortcut notation of allowing
named form controls to be accessed as named members of the form object
will mean that the - length - property of the form will have been
replaced with a reference to the same form control.


I seem to be overlooking a lot of details today...

Thank you. I'd also like to thank you for your advice on DOM feature
detection given last week (23rd).

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #5
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:op**************@news-text.blueyonder.co.uk...
<snip>
I seem to be overlooking a lot of details today...
So am I. I forgot about textarea elements.
... . I'd also like to thank you for your advice on
DOM feature detection ...


You are welcome. It is probably one of the most important aspects of
matching a script with a browser's possible support for it and deserves
talking about from time to time.

Richard.
Jul 20 '05 #6
On Mon, 2 Feb 2004 23:00:38 -0000, Richard Cornford
<Ri*****@litotes.demon.co.uk> wrote:
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:op**************@news-text.blueyonder.co.uk...
I seem to be overlooking a lot of details today...


So am I. I forgot about textarea elements.


I actually noticed that. :) For thoroughness, you could also mention
BUTTON elements, but they wouldn't be accessed nearly as much.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #7
la***********@zipmail.com (D. Alvarado) wrote in
news:9f**************************@posting.google.c om:
Hello, I'm having problems on IE 6.0 for Win XP. I want to iterate
through the elements of a form, but one of those elements is named
'length'. So, this JS code doesn't display any alert boxes, even
though it should display 3.

for (var i=0; i<myForm.elements.length; i++) {
alert(myForm.elements[i].name);
}

Can anyone suggest a cross-browser work-around? Thanks -


Umm, am I missing something? Why not just change the name of the element
named 'length'?

John
Jul 20 '05 #8
John <jo**@mshome.net> wrote in message news:<Xn***************************@203.26.24.228> ...
la***********@zipmail.com (D. Alvarado) wrote in
news:9f**************************@posting.google.c om:

Umm, am I missing something? Why not just change the name of the element
named 'length'?

John


Normally a good idea. I do not have control over the variable name --
it is required by a third party site to which I'm passing data.

Thanks to all for the helpful answers. -
Jul 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Michael Bierman | last post by:
Please forgive the simplicy of this question. I have the following code which attempts to determine the color of some text and set other text to match that color. It works fine in Firefox, but does...
6
by: Luke Dalessandro | last post by:
I'm not sure if this is the correct forum for platform specific (Mozilla/Firefox) javascript problems, so just shout and point me to the correct newsgroup if I'm being bad. Here's the deal... ...
1
by: jason.lucey | last post by:
Hi, I cannot get this figured out. I need to get the text out of an element node. In IE, I can do it like this: xNode(0).text but that does not work for Mozilla. And since element nodes...
8
by: Doug Lerner | last post by:
I have this snippet of client side code running: var makeField = document.forms; alert("makeFieldName name,length,type=" + makeFieldName + ", " + makeField.name + "," + makeField.length + ","...
14
by: hgraham | last post by:
Hi, I'm trying to understand how to work the dom, and all I'm trying to do is insert a link right before another link in the html based on it's href value. This isn't a real world example - I'm...
17
by: pbd22 | last post by:
hi. i keep getting this error. as i understand it, my xml isn't formatted correctly. the online errata suggests the standard formatting to solve this problem: element (tab) (tab) element
2
dlite922
by: dlite922 | last post by:
Before traversing my code, here's what my goal is and what this function does: I have a table of fields that dynamically grows as the user enters information. A minimum of 3 rows must always...
7
by: andrewb | last post by:
Hi all, Having some trouble using named pipes and Visual Basic .NET and would appreciate and help you could offer. Essentially I am trying to develop a simple client/server application that...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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
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
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
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...

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.