470,563 Members | 2,427 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,563 developers. It's quick & easy.

Form field with same name as js form property--workaround?

I'm trying to do some javascript form validation and I've discovered a
rather difficult situation to handle with IE.

Let's say there's a form with three input fields named "name",
"method", or "length". Whenever my javascript tries to access the
form's name or length, and the form happens to have input fields named
"name" and "length", I'm actually accessing the input fields and there
seems to be no way to access those properties of the form.

I have an easy workaround for form.length, so there's no need to give
me a workaround for that one, but there's a bigger issue with fields
like name, method, action, etc.

For example, using document.forms[0].name to get the name of the form
seems to map to document.forms[0].elements["name"] istead of the
actual name of the form. Is there a work around for this? I am
writing some generic form validation code, and I can't expect the
person implementing my form validation code to avoid using "name" and
"length" as names for their form fields.

Thanks in advance,
RN
Jul 23 '05 #1
1 3101


Ronaldo N wrote:
I'm trying to do some javascript form validation and I've discovered a
rather difficult situation to handle with IE.

Let's say there's a form with three input fields named "name",
"method", or "length". Whenever my javascript tries to access the
form's name or length, and the form happens to have input fields named
"name" and "length", I'm actually accessing the input fields and there
seems to be no way to access those properties of the form.

I have an easy workaround for form.length, so there's no need to give
me a workaround for that one, but there's a bigger issue with fields
like name, method, action, etc.

For example, using document.forms[0].name to get the name of the form
seems to map to document.forms[0].elements["name"] istead of the
actual name of the form. Is there a work around for this? I am
writing some generic form validation code, and I can't expect the
person implementing my form validation code to avoid using "name" and
"length" as names for their form fields.


As long as you are looking for HTML attributes like action or method or
name with Mozilla you can use
formObject.getAttribute('action')
formObject.getAttribute('method')
formObject.getAttribute('name')
however with IE (at least IE/Win) that doesn't help as IE somehow
confuses HTML attributes and DOM properties and fails to return the HTML
attribute value if the form element object has a property of the same name.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by xenophon | last post: by
3 posts views Thread by markux | last post: by
1 post views Thread by =?Utf-8?B?RGFu?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.