By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,969 Members | 2,360 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,969 IT Pros & Developers. It's quick & easy.

How can I pass trough all objects of a form, if some of them are contained in divs?

P: n/a
Hi!

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.

I'm doing something like:

for (i = 0; i < document.forms(0).item.length; i++) {
dosomethingwith(document.forms(0).item(i));
}

but document.forms(0).item.length are the objects that are outside the
DIVs...

How can I pass trough all the objects of a form if some of them are
contained in divs?

Thanks a Lot!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Andrés Giraldo <an************@yahoo.com> writes:
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.
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.
for (i = 0; i < document.forms(0).item.length; i++) {
dosomethingwith(document.forms(0).item(i));
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

but document.forms(0).item.length are the objects that are outside the
DIVs...
Huh?
The above code iterates through all form controls, and nothing else.
The div's have no influence on this at all.
How can I pass trough all the objects of a form if some of them are
contained in divs?


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 - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.