Connecting Tech Pros Worldwide Help | Site Map

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

Marc Elser
Guest
 
Posts: n/a
#1: Jul 23 '05
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
Martin Honnen
Guest
 
Posts: n/a
#2: Jul 23 '05

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




Marc Elser wrote:

[color=blue]
> 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.[/color]

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/
Lee
Guest
 
Posts: n/a
#3: Jul 23 '05

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


Marc Elser said:[color=blue]
>
>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>[/color]

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?

Antonie C Malan Snr
Guest
 
Posts: n/a
#4: Jul 23 '05

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


Martin Honnen wrote:[color=blue]
>
>[/color]
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
[color=blue]
> Marc Elser wrote:
>
>[color=green]
>> 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.[/color]
>
>
> 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.
>
>[/color]


Antonie C Malan Snr
Guest
 
Posts: n/a
#5: Jul 23 '05

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


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

Closed Thread