473,218 Members | 1,479 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,218 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 3927


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,...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.