Link to home
Start Free TrialLog in
Avatar of ysre
ysreFlag for Afghanistan

asked on

Finding an <input>'s <form>-parent via DOM?

Hi,

I'm just wondering..
How would you walk the DOM-tree in order to find the parent <FORM> element (eg. to submit() it) of any given <INPUT> element?

Example:
<form action="sth"> <!-- no name or id or class! -->
<input type="text" onClick="alert (find_parental_form_element(this))">
<input type="text" onClick="alert (find_parental_form_element(this))">
<input type="text" onClick="alert (find_parental_form_element(this))">
</form>

Walking via .parentNode only returns me styling - type elements (eg. in this order: DIV, TD, TR, TBODY, TABLE).

Ys
Avatar of ysre
ysre
Flag of Afghanistan image

ASKER

Never mind, found a (kinda quirky) solution already.

I'm walking back via .parentNode until I find a node that has a childnode which has a nodeName of "FORM" ;)

Ys
SOLUTION
Avatar of clockwatcher
clockwatcher

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ysre

ASKER

Hm yeah, I added some prerequisites (that's why I called it quirky).
Just wanted to find out if you can do it via the appraised ;) DOM 1 model.
Apparently you can't really.

Unless you use the old-style document.forms approach (or getElementsByTagName for firefox).

Thanks for the insight :)

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ysre

ASKER

Hmpf sometimes things can be so easy..
Funny it never showed up in the properties' listing for the element(s).

Thanks :)