469,282 Members | 1,701 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

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 3731


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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Java script Dude | last post: by
13 posts views Thread by dhughey | last post: by
6 posts views Thread by Dick Watson | last post: by
9 posts views Thread by scripteaze | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.