[thelist] Form sniffing within tables nested within divs

Chris Marsh chris at webbtech.co.uk
Wed Nov 6 14:00:01 CST 2002


Roger

> What about something like this:
>
> function doIndividualFormStuff(formObject) {
> 	alert(formObject.name);
> }
>
> function doFormsStuff(divID) {
> 	for (i = 0; i < document.all[divID].all.length; i++)
> 	{
> 		var object = document.all[divID].all[i];
> 		if (object.elements)
> 		{
> 			// if object.elements exists, it is a form
> object
> 			doIndividualFormStuff(object);
> 		}
> 	}
> }
>
> since elements is only a property of a form object, checking
> the existence of that property is a quick and dirty way of
> determining if you are dealing with a form element.  Also,
> since you are only iterating through the objects of a
> particular div (as referenced by document.all[divID]), it
> should only return form objects in that div.
>
> If you want to get all the form objects in the divs within
> the divs, I'm sure you can alter the code to traverse the
> children of the top-most div.

I think I'm urinating out of an area of low pressure if I'm honest with
myself. I'm dealing with legacy code and haven't got the time to change
the entire system right now. The problem is that because of how the html
is generated I don't know if the the form is in the div, a table cell
within a table within the div, a div within a table cell within a table
within the div etc. etc. Thank you all for your help, but I must get
this done tonight. Consequently I guess I'll have to approach it another
way.

Thanks again.

Regards

Chris Marsh





More information about the thelist mailing list