On Apr 5, 1:13 pm, "mare...@gmail.com" <mare...@gmail.comwrote:
Hi,
Let's say we have the following html code (a body with some forms):
<html>
<head>
</head>
<body>
<form name="form1" action="#">
<input type="image"
onmouseover="print_form_name()"
alt="Send"
value="1"
name="Send"
src="submit.gif"/>
</form>
<form name="form2" action="#">
<input type="image"
onmouseover="print_form_name()"
alt="Send"
value="2"
name="Send"
src="submit.gif"/>
</form>
</body>
</html>
I'm interested in the code of print_form_name() function. How can i
make it return the form handle, or run an alert with the form name, or
show me a list of controls of the current form (this is what i want).
Thanks in advance.
Regards,
Marius.
well, here's a kind of fragile way to do it:
alert(this.parentNode.name);
in other words, your HTML would look like <input ...
onmouseover="alert(this.parentNode.name);" ... />
that should work, assuming that the <inputelement is the direct
child of the <formelement (like what you have now). if you were to,
say, put a table inside the <form>, and put the <inputinside the
table, it wouldnt work anymore because the code "this.parentNode"
would be getting the wrong element (probably a <tdor something like
that).
you could also try this:
alert(this.form.name);
it looks like that will work in firefox, but i'm not sure about other
browsers. i dont think that way is "proper" DOM, but it would
certainly be easier.