473,397 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Forms array peculiarities

I have a form which contains quantity and subtotal input boxes for
ordering things, i use javascript to calculate the value to be placed
in the subtotal box by iterating through a document.myForm[] array
(where myForm is the name of the form). The indexing I use works fine
in IE6 and Firefox 0.10.1, however when testing in NN6, i noticed that
the myForm[] array was also including <label> elements, whereas in ie6
and ff it only includes the input boxes. I have managed to detect when
this occurs and change the index for when this occurs, however I would
like to know whether any other browsers have quirks like this, I don't
particularly want to have to install IE4 or 5.5 etc...

Which is more compatible:
document.myForm.item1Quantity.value or
document.myForm[0].value
for referencing form elements?
Jul 23 '05 #1
2 1213


Bonnett wrote:
I have a form which contains quantity and subtotal input boxes for
ordering things, i use javascript to calculate the value to be placed
in the subtotal box by iterating through a document.myForm[] array
(where myForm is the name of the form). The indexing I use works fine
in IE6 and Firefox 0.10.1, however when testing in NN6, i noticed that
the myForm[] array was also including <label> elements, whereas in ie6
and ff it only includes the input boxes. I have managed to detect when
this occurs and change the index for when this occurs, however I would
like to know whether any other browsers have quirks like this, I don't
particularly want to have to install IE4 or 5.5 etc...
In current browsers like IE 6, Netscape 7, Opera 7 <fieldset> elements
are also contained in the elements collection of a <form> element.
Which is more compatible:
document.myForm.item1Quantity.value or
document.myForm[0].value
for referencing form elements?


Use
document.forms.myForm.elements
to loop through, then check tagName of the element you are acessing.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
Bonnett wrote:
I have a form which contains quantity and subtotal input boxes for
ordering things, i use javascript to calculate the value to be placed
in the subtotal box by iterating through a document.myForm[] array
(where myForm is the name of the form). The indexing I use works fine
in IE6 and Firefox 0.10.1, however when testing in NN6, i noticed that
the myForm[] array was also including <label> elements, whereas in ie6
and ff it only includes the input boxes. I have managed to detect when
this occurs and change the index for when this occurs, however I would
like to know whether any other browsers have quirks like this, I don't
particularly want to have to install IE4 or 5.5 etc...

Which is more compatible:
document.myForm.item1Quantity.value or
document.myForm[0].value
for referencing form elements?


document.forms['myFormName'].elements['myControlName'].value

should work in any user agent that understands forms and client-side
JavaScript. Using bracket notation on the collections also avoids any
problems when you begin to work with scripts that can read input from a
variety of inputs, decided at run-time:

var myControlNameVariable = 'myControl' + 'Name';
document.forms['myFormName'].elements[myControlNameVariable].value;

All of this depends on your form having the general layout:

<form name="myFormName" id="myFormId" ...>
<input type="text" name="myControlName" id="myControlId" ...>

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #3

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

Similar topics

8
by: Alex Vinokur | last post by:
Various forms of argument passing ================================= C/C++ Performance Tests ======================= Using C/C++ Program Perfometer...
4
by: David | last post by:
Hello. I am looking for advice on what is "best practice" regarding looping through a form to check its checkboxes and associated data fields. Here is what I am trying to do (Here is the page...
4
by: Omar | last post by:
Hi, I've been working with this without problems: function regresaValor() { var indexValor = document.forms.eleccion.selectedIndex; var valueValor = document.forms.eleccion.options.value;...
6
by: Otie | last post by:
I have a project with a main form and a second form with a grid on it. Neither form is an MDI, thus neither form is a child - they are two independent forms. The CALCULATE button on the main form...
204
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 =...
9
by: JW | last post by:
Dear NG, Still working on my .NET CF C# forms application ... I have an array of forms that I wish to display in array order, and thus have created a loop to run through them. Due to...
9
by: Serg | last post by:
I have a form with a text input field Is it possible to specify NO border on that field? Obviosuly I tried border="0" but to no avail. Thanks ahead,
21
by: MLH | last post by:
Am having trouble with the following snippet. It stops after only cycling thru open forms. There are many more than that. How to modify this to cycle thru all forms? Sub AllOpenForms() Dim...
19
Atli
by: Atli | last post by:
Introduction At some point, all web developers will need to collect data from their users. In a dynamic web page, everything revolves around the users input, so knowing how to ask for and collect...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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
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...
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,...

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.