Andrés Giraldo <andres_giraldo@yahoo.com> writes:
[color=blue]
> I'm trying to pass trough all the objects of a form but I have some text
> inputs in a DIV and I have many DIVs like this on my form.[/color]
What, exactly, do you mean by "all the objects of a form"?
If you only want to access the actual form controls (input, select,
textarea elements), then what you do is close to correct:
for (var i=0;i<document.forms[0].elements.length; i++) {
dosomethingwith(document.forms[0].elements[i]);
}
Use square brackets! Both forms and elements are collections, not
functions.
[color=blue]
> for (i = 0; i < document.forms(0).item.length; i++) {
> dosomethingwith(document.forms(0).item(i));[/color]
This makes a lot of assumptions.
document.forms is a collection. It has a method called "item" that you can use to access the parts of the collection, or you can use square bracket notation.
document.forms.item(0) or document.forms[0]
However, IE shares the same object for both the forms collection and the
item function ("document.forms == document.forms.item" is true), so you
can get away with writing "document.forms(0)". Most other browsers wouldn't
accept that.
Likewise, in IE, for a form,
form == form.elements and form == form.elements.item
[color=blue]
> but document.forms(0).item.length are the objects that are outside the
> DIVs...[/color]
Huh?
The above code iterates through all form controls, and nothing else.
The div's have no influence on this at all.
[color=blue]
> How can I pass trough all the objects of a form if some of them are
> contained in divs?[/color]
Div's make no difference (unless you are using Netscape 4 and
positioned divs, which it interprets as layers and therefore separate
documents).
/L
--
Lasse Reichstein Nielsen -
lrn@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'