473,386 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 3199


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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bharat Suneja | last post by:
Hi All, I'm running into issues with passing the distinguishedName of a user as a hidden form field in a form from one page to the result page. Page 1: User enters user name in a form field ...
4
by: Marc Elser | last post by:
Hi Everybody, Can someone please tell me how to access the form name if there's a form field named "name", for example: <form name="myform"> <input type="text" name="name" value="Marc">...
3
by: Pavils Jurjans | last post by:
Hello, I have bumped upon this problem: I do some client-side form processing with JavaScript, and for this I loop over all the forms in the document. In order to identify them, I read their...
3
by: Li Zhang | last post by:
I know I can use controlName.Value to retrieve the form fields value if I am in that page. But if I am out of the page, for example I am in a HttpModule, I want to retrieve a hidden filed value, Is...
2
by: xenophon | last post by:
I added a Hidden Form Field to a form in the code behind. The value is being set in JavaScript client-side, but it is not persisting to the server in the PostBack. I know the value is being set...
1
by: tomlebold | last post by:
Having problems displaying query results from combo boxes on a sub form, which is on the same form that is used to select criteria. This has always worked form me when displaying query results on...
3
by: markux | last post by:
Hi, I have a problem with a form that it has of the input with the same name: I cannot modify code HTML inserting , in the variable $_POST is always a single value, like I can recover also the...
1
by: viksha | last post by:
Hi, I need help to get sum of field in subform to main form field I am using Mainform's field (total) default value =Sum(!!) Please help
1
by: =?Utf-8?B?RGFu?= | last post by:
I am posting data to a form using the code below (from a console app). My problem is that I'm posting my data as a generic request stream, and the page is expecting the data to have come from a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.