473,402 Members | 2,055 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,402 software developers and data experts.

How To access form name if there's a form field named "name"

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">
<input type="button" onClick="alert(this.form.name);">
</form>

When I do this, the alert shows "[object HTMLInputObject]" (in firefox)
or just "[object]" (in ie6) instead of the string "myform".

the problem is that I access the form element named "name" instead of
the forms name property.

Problem is this is a simplified example, in my real program there's
nothing I an do about the input elements name or else the cgi program
which receives the form values crashes, means i cannot change "<input
type="text" name="name"...>" to let's say <input type="text"
name="surname">".

Is there any solution to this problem? Thanks for any help. I suppose
there is some way of accessing the form's name property with the correct
notation.

Thanks for every help I can get
Jul 23 '05 #1
4 3936


Marc Elser wrote:

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">
<input type="button" onClick="alert(this.form.name);">
</form>

When I do this, the alert shows "[object HTMLInputObject]" (in firefox)
or just "[object]" (in ie6) instead of the string "myform".

the problem is that I access the form element named "name" instead of
the forms name property.

Problem is this is a simplified example, in my real program there's
nothing I an do about the input elements name or else the cgi program
which receives the form values crashes, means i cannot change "<input
type="text" name="name"...>" to let's say <input type="text"
name="surname">".

Is there any solution to this problem? Thanks for any help. I suppose
there is some way of accessing the form's name property with the correct
notation.


With Mozilla I think it works to read
form.getAttribute('name')
but IE messes things up when it comes to distinguishing between HTML
attributes and JavaScript properties.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
Lee
Marc Elser said:

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">
<input type="button" onClick="alert(this.form.name);">
</form>


Looking at the problem from a different direction,
are you sure you really need the form's name?
Is there any other way of identifying it that would work?

Jul 23 '05 #3
Martin Honnen wrote:

Give the text from element named "name" an id which is unique on the
page (maybe even the site). Like this: id="myName"

Now get the from element named "name" as an object like this:
var theName = document.getElementById("myName");

Now display the value in theName - you want it as an alert, therefore
like so:

alert(theName.value);

Works in MSIE and Netscape/Mozilla derivates.

That's it.

Chris
Marc Elser wrote:

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">
<input type="button" onClick="alert(this.form.name);">
</form>

When I do this, the alert shows "[object HTMLInputObject]" (in
firefox) or just "[object]" (in ie6) instead of the string "myform".

the problem is that I access the form element named "name" instead of
the forms name property.

Problem is this is a simplified example, in my real program there's
nothing I an do about the input elements name or else the cgi program
which receives the form values crashes, means i cannot change "<input
type="text" name="name"...>" to let's say <input type="text"
name="surname">".

Is there any solution to this problem? Thanks for any help. I suppose
there is some way of accessing the form's name property with the
correct notation.

With Mozilla I think it works to read
form.getAttribute('name')
but IE messes things up when it comes to distinguishing between HTML
attributes and JavaScript properties.

Jul 23 '05 #4
Hi All,

This is a sticky problem. Nevertheless, there should be an answer
somewhere.

I have a form table that changes dynamically as a result of selecting a
value in a Select. This can be seen at (I'll try html here) <a
href="http://members.optusnet.com.au/~malan2000/PCN/dealer.html"
target="_blank">this url</a>

As you can see, the elements get created fine. The problem is that none
of the values of the created elements get parsed by my servlet.

This is the code that generates one checkbox:

var contentPlace = document.getElementById("contentPlace");
var cell = document.createElement("TD");
cell.id="contentCell";
cell.colSpan= 9;
cell.align="center";
var text1 = document.createTextNode("Auto");
var input1 = document.createElement("Input");
input1.name="auto";
input1.value="auto";
input1.type="CheckBox";
contentPlace.appendChild(cell);
cell.appendChild(text1);
cell.appendChild(input1);

If I view Page Info in Mozilla all the elements of the form are there.

Any idea how to get this to work?

Thanks,

Chris

Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John Davis | last post by:
I want to know what's the differences between Request.Form("Field Name") and Request.QueryString("Field Name") OR they function exactly the same, which is to return the value of the field?? ...
6
by: Java script Dude | last post by:
We just discovered another IE bug. When an html form contains an element with a name of `name` IE's internal index screws up the .name property of the containing form to point to the bad element...
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...
13
by: dhughey | last post by:
I am using <script type="text/javascript"> function setAction(frm){ act = ''; for(x=0;x<frm.se.length;x++){ if(frm.se.checked){ act = frm.se.value; } }
6
by: Dick Watson | last post by:
I had a page that works when setup like this: === <form name="frmCalc" action=""> <script type="text/javascript"> function btnCalc_onclick(abc) { return "got here with " + abc; }
6
by: karen987 | last post by:
I have a webpage called "topicview.asp" on a news website with ASP pages, it's a simple news publishing software. You add the news from the Admin section and all the details are stored in a...
1
by: mark | last post by:
Forgive me if this seems like a stupid question but I need help... I'm trying to do a simple online form that emails me the results from a few fields. Here is the code: <form...
9
by: scripteaze | last post by:
Im using mechanize method for retrieving the form so that i may log into it. I need to find a way to get the form name. Its not listed anywhere in the html source.The reason i need to do this is...
4
by: KrazyKasper | last post by:
I'm a Novice User using Access 2003 Tables are via ODBC (i.e., cannot alter fields) I have a report that uses the field OrderRepName (text string) and is formatted as lastname, firstname,...
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: 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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.