form property and object

M

mathieu gagnon

Hello,

I'm new to this newsgroup and I have small question.

With something like this : <form name="a"><input name="name"></form>
Is it possible to get the name of the form (a) and access the input object
(name) too ?

Thanks,
/mathieu
 
M

Mathieu Gagnon

If I try...

<form name="a"><input name="name"></form>
alert(document.forms[0].elements[1].name)
alert(document.forms[0].name)

The first alert gives "name", the second : "[object]".
What I need is "a" alerted without changing the name of the input.

Thanks,
/mathieu

HikksNotAtHome said:
"mathieu gagnon" said:
I'm new to this newsgroup and I have small question.

With something like this : <form name="a"><input name="name"></form>
Is it possible to get the name of the form (a) and access the input object
(name) too ?

Thanks,
/mathieu


<form name="myForm">
<input type="button" onclick="alert(this.form.name)"
value="Click Me to see the Forms Name">
<input type="button" onclick="alert(this.name)"
value="Click Me to see My Name" name="myInput">
<input type="button"
onclick="alert('This input is in the ' + this.form.name + ' form. And my
input name is ' + this.name)"
value="Click Me to see the Forms Name and My Name" name="myInput2">
</form>

alert(document.forms[0].elements[1].name)
alert(document.forms[0].name)

In short, you access the form elements name property, or the elements name
property.

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
474,079
Messages
2,570,575
Members
47,207
Latest member
HelenaCani

Latest Threads

Top