forms[0].elements

K

Kroska

Can I make a array with all form elements?

to event keydown I think use esc[27] to return or enter[13] to next
field.(my client order it)
To my tast it is bad but .. I can´t to oppose.

How I can write a array with all form elements and after to work with
each item?

x = document.forms[0].elements

x = document.forms[0].elements.length

can someone help me?
 
R

RobG

Can I make a array with all form elements?

to event keydown I think use esc[27] to return or enter[13] to next
field.(my client order it)
To my tast it is bad but .. I can´t to oppose.

How I can write a array with all form elements and after to work with
each item?

x = document.forms[0].elements

That returns an HTML collection of all the controls in the form:

<URL: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-76728479 >

An HTML collection is an array-like structure that you can use to
access each control by index. The index is assigned based on the
control's position in the DOM (essentially the order they appear in
the HTML).

x = document.forms[0].elements.length

The length property tells you how many controls are in the collection,
so:

var x = document.forms[0].elements
for (var i=0, len=x.length; i<len; i++) {
var control = x;
// do stuff with the control
}

As the elements collection is live, the length property will change if
controls are added or removed from the form. So if "do stuff" adds or
removes controls, you'll have include logic to handle that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top