how can i retrieve the name of form when one of the element name in this form is 'name'

A

ashok.dhananjeyan

Hi,

Actually , I wrote one javascript to retrieve the name of the form in
one particular page.
what i did in this page is,

<script>

function checkbutton()
{
var f = document.forms("myform");

alert(f) ;

alert(f.name) ;

alert(f.name.value) ;

}


</script>


<html>

<body>

<form name="myform" >

Click Here to check the value of name button
<input type=button name='name' value='Click Here'
onclick='checkbutton();' >
</form>
</body>

</html>

but i can not able to retrieve the name of the form , only i get the
object of element.so how can i get the form name.

there is any other way to get the form name. or element name cannot be
a 'name'.

Please reply me ASAP.


Regards
Ashok D.
 
R

Randy Webb

(e-mail address removed) said the following on 11/22/2006 11:47 PM:
Hi,

Actually , I wrote one javascript to retrieve the name of the form in
one particular page.

Trivial. Was there a question?
what i did in this page is,

<script>

function checkbutton()
{
var f = document.forms("myform");

alert(f) ;

alert(f.name) ;

alert(f.name.value) ;

}

Ok. Is there a question?
</script>


<html>

<body>

<form name="myform" >

Click Here to check the value of name button
<input type=button name='name' value='Click Here'
onclick='checkbutton();' >
</form>
</body>

</html>

but i can not able to retrieve the name of the form , only i get the
object of element.so how can i get the form name.

Change the name of your input to something besides name that isn't in
the forms collection.
there is any other way to get the form name. or element name cannot be
a 'name'.

Rename your input.
 
R

RobG

there is any other way to get the form name. or element name cannot be
a 'name'.

In Firefox and Opera you can use getAttribute, but since that doesn't
work for IE you are back to what Randy said - don't give any element a
name of "name".

<form name="Fred">
<input type="button" name="name" value="Show form name"
onclick="alert(this.form.getAttribute('name'));">
</form>
 
V

VK

Actually , I wrote one javascript to retrieve the name of the form in
one particular page.
<form name="myform" >

Click Here to check the value of name button
<input type=button name='name' value='Click Here'
onclick='checkbutton();' >
</form>

As it was already suggested, there are two forbidden names for form
elements you *never ever* use unless with a gun against your temple:
"name" and "submit". Each of them means huge scripting troubles in the
immediate future.

But presuming that you have to deal with a 3rd party form and there is
absolutely no way to insist on server-side changes...

Normally when you are using DOM 0 methods the engine understands that
you are willing to reach form elements and when you are using
getAttribute then the engine understands that you want to reach element
attributes. That works for all browsers except IE which presumes by
default that all users are idiots and what they asking for is not what
they really want (thus on getAttribute it still returns element from
form collection). This way the task is to bypass somehow this "parasite
neuristic". They way we are suggesting to our clients is:

....
// Please note that DOM 0 uses squared brakets
// notation, not parenthesis like in your original code.
// Otherwise it will break out on any normal browser:
var f = document.forms["myform"];

alert(f); // form object

alert(f.attributes.getNamedItem('name').nodeValue) // form name;

alert(f.elements['name'].value) ;
 
R

Randy Webb

VK said the following on 11/23/2006 6:54 AM:
As it was already suggested, there are two forbidden names for form
elements you *never ever* use unless with a gun against your temple:
"name" and "submit". Each of them means huge scripting troubles in the
immediate future.

Congratulations, you just named 2 of the 100 or so name/IDs that come to
mind as potentially causing a problem. Try using dot notation while
naming your form "links", or "images" or......
 
V

VK

As it was already suggested, there are two forbidden names for form
Congratulations, you just named 2 of the 100 or so name/IDs that come to
mind as potentially causing a problem. Try using dot notation while
naming your form "links", or "images" or......

I listed two names *for form elements* (not forms themselves) which are
causing problems with *any* notation. Maybe I should say "controls
inside the form" to avoid possible confusion. Yet the form collection
is called "elements" and the whole context (with code provided) was
very clear... OK, rather than arguing::

"There are two forbidden names for controls inside your form which you
*never ever* use unless with a gun against your temple: "name" and
"submit" (all in lower case). Each of them means huge scripting
troubles in the immediate future."
 
R

RobG

VK said:
I listed two names *for form elements* (not forms themselves)

I think you mean form controls.
which are
causing problems with *any* notation. Maybe I should say "controls
inside the form" to avoid possible confusion.

To be a control, an element *must* be inside the form (and have a name
attribute). To avoid confusion, call them form controls.
Yet the form collection
is called "elements" and the whole context (with code provided) was
very clear...

The collection of forms is called "forms", the collection of a
particular form's controls is called "elements". Your post wasn't
clear about that at all.

Note to W3C: why wasn't the collection of controls called "controls"?
OK, rather than arguing::
"There are two forbidden names ... "name" and "submit"

And *any other property* that a form might have, such as reset,
nodeName, nodeValue, nodeType, prefix, localName, tagName, title, lang,
action, method, etc. As Randy said, there are about 100 of them (IE
has over 130). It is one reason to recommend the use of the more
formal forms[formName].elements[elementName] over simpler dot property
access.
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top