Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is there any way to change the "name" of one element?

0 views
Skip to first unread message

jidix...@gmail.com

unread,
Aug 1, 2007, 7:15:25 AM8/1/07
to
Hi,everyone!
Is there any way to change the "name" of one element?
Please look some simple code as following first:


[code]
<form name="form1" method="post" action="">
<input type="text" id="spp" value="1" />
<input type="text" name="dlp" class="asd" readonly>
</form>
<script language="JavaScript">
document.getElementById("spp").id="a";
alert(document.getElementById("a").value);
</script>
[/code]


It works fine!
But the following do not.

[code]
<form name="form1" method="post" action="">
<input type="text" id="spp" value="1" />
<input type="text" name="dlp" class="asd" readonly>
</form>
<script language="JavaScript">
document.getElementsByName("spp")[0].name = "a";
alert(document.getElementsByName("a")[0].value);
</script>
[/code]

Randy Webb

unread,
Aug 1, 2007, 8:25:48 AM8/1/07
to
jidix...@gmail.com said the following on 8/1/2007 7:15 AM:

Stop trying to make things harder than they are. Use the forms
collection and life is so much simpler:

<form name="form1" method="post" action="">
<input type="text" id="spp" value="1" />
<input type="text" name="dlp" class="asd" readonly>
</form>
<script language="JavaScript">

document.form1.elements['spp'].name = "a";
alert(document.form1.elements['a'].value);
</script>

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?

jami...@gmail.com

unread,
Aug 1, 2007, 2:04:58 PM8/1/07
to
On Aug 1, 7:15 am, "jidixuel...@gmail.com" <jidixuel...@gmail.com>
wrote:

If we were to just correct what you did, change the one line to:

document.getElementById("spp")[0].name = "a";

jidix...@gmail.com

unread,
Aug 1, 2007, 7:15:06 PM8/1/07
to
On Aug 1, 7:15 pm, "jidixuel...@gmail.com" <jidixuel...@gmail.com>
wrote:


I'm so sorry I did not describe the detail.
the second code block should be :

[code]
<form name="form1" method="post" action="">

<input type="text" name="spp" value="1" />


<input type="text" name="dlp" class="asd" readonly>
</form>
<script language="JavaScript">
document.getElementsByName("spp")[0].name = "a";
alert(document.getElementsByName("a")[0].value);
</script>
[/code]

It didn't work only in IE!
I can not change a name of one HTMLelement!
Is the "name" a readonly attribute in IE????

jidix...@gmail.com

unread,
Aug 1, 2007, 7:21:54 PM8/1/07
to
> document.getElementById("spp")[0].name = "a";- Hide quoted text -
>
> - Show quoted text -


I'm so sorry!
You misunderstand my mean just as I did not understand your mean!
Because I write a wrong code block! I'm so sorry!
But the question is continue,please look the upper!

Thomas 'PointedEars' Lahn

unread,
Aug 2, 2007, 3:06:22 AM8/2/07
to
Randy Webb wrote:
> <form name="form1" method="post" action="">
> <input type="text" id="spp" value="1" />
> <input type="text" name="dlp" class="asd" readonly>
> </form>
> <script language="JavaScript">
> document.form1.elements['spp'].name = "a";
> alert(document.form1.elements['a'].value);

document.forms["form1"].elements[...]

> </script>


PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16

Thomas 'PointedEars' Lahn

unread,
Aug 2, 2007, 3:14:17 AM8/2/07
to
jidix...@gmail.com wrote:
> <script language="JavaScript">

<script type="text/javascript">

> document.getElementsByName("spp")[0].name = "a";
> alert(document.getElementsByName("a")[0].value);
> </script>
> [/code]
>
> It didn't work only in IE!
> I can not change a name of one HTMLelement!
> Is the "name" a readonly attribute in IE????

It is not, however the name change is described as not being reflected
in the DOM:

http://msdn2.microsoft.com/en-us/library/ms534184.aspx

Your Question Mark key is borken.


PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not the
best source of advice on designing systems that use javascript.
-- Richard Cornford, <f806at$ail$1$8300...@news.demon.co.uk>

Randy Webb

unread,
Aug 2, 2007, 3:15:57 AM8/2/07
to
Thomas 'PointedEars' Lahn said the following on 8/2/2007 3:06 AM:

> Randy Webb wrote:
>> <form name="form1" method="post" action="">
>> <input type="text" id="spp" value="1" />
>> <input type="text" name="dlp" class="asd" readonly>
>> </form>
>> <script language="JavaScript">
>> document.form1.elements['spp'].name = "a";
>> alert(document.form1.elements['a'].value);
>
> document.forms["form1"].elements[...]

In this instance, they are equivalent and no point in pointing out any
differences. Well, other than to be pedantic.

> PointedEars

If you don't want your "Name Signature" quoted, then please properly
delimit it. Thank you for your cooperation in the future.

Thomas 'PointedEars' Lahn

unread,
Aug 2, 2007, 3:20:07 AM8/2/07
to
Randy Webb wrote:
> Thomas 'PointedEars' Lahn said the following on 8/2/2007 3:06 AM:
>> Randy Webb wrote:
>>> <form name="form1" method="post" action="">
>>> <input type="text" id="spp" value="1" />
>>> <input type="text" name="dlp" class="asd" readonly>
>>> </form>
>>> <script language="JavaScript">
>>> document.form1.elements['spp'].name = "a";
>>> alert(document.form1.elements['a'].value);
>> document.forms["form1"].elements[...]
>
> In this instance, they are equivalent [...]

They are not. The latter is part of a Web standard (W3C DOM Level 2
HTML), the former is not. You are relying on that specification to
refer to an ID-ed element with the `elements' HTMLCollection here, so
you have to stick to it for the whole reference (and all references
here) in order not to write error-prone code.

Randy Webb

unread,
Aug 2, 2007, 3:21:41 AM8/2/07
to
Thomas 'PointedEars' Lahn said the following on 8/2/2007 3:14 AM:

> jidix...@gmail.com wrote:
>> <script language="JavaScript">
>
> <script type="text/javascript">

Deprecated.

>> document.getElementsByName("spp")[0].name = "a";
>> alert(document.getElementsByName("a")[0].value);
>> </script>
>> [/code]
>>
>> It didn't work only in IE!
>> I can not change a name of one HTMLelement!
>> Is the "name" a readonly attribute in IE????
>
> It is not, however the name change is described as not being reflected
> in the DOM:
>
> http://msdn2.microsoft.com/en-us/library/ms534184.aspx

Then why did the code I posted change it?

> Your Question Mark key is borken.

No, it wasn't. It appears to have worked just fine. Four times in fact.

Your spell checker is broken though.

Thomas 'PointedEars' Lahn

unread,
Aug 2, 2007, 3:45:00 AM8/2/07
to
Randy Webb wrote:
> Thomas 'PointedEars' Lahn said the following on 8/2/2007 3:14 AM:
>> jidix...@gmail.com wrote:
>>> <script language="JavaScript">
>> <script type="text/javascript">
>
> Deprecated.

Don't be ridiculous. You know very well that it is still the most
widely supported media type for client-side scripting, no matter what
the *informational* RFC4329 says.

I have posted http://pointedears.de/scripts/test/mime-types/ here before.

>>> document.getElementsByName("spp")[0].name = "a";
>>> alert(document.getElementsByName("a")[0].value);
>>> </script>
>>> [/code]
>>>
>>> It didn't work only in IE!
>>> I can not change a name of one HTMLelement!
>>> Is the "name" a readonly attribute in IE????
>> It is not, however the name change is described as not being reflected
>> in the DOM:
>>
>> http://msdn2.microsoft.com/en-us/library/ms534184.aspx
>
> Then why did the code I posted change it?

Probably because of different DOM levels used, which would only be
another peculiarity of the MSHTML DOM. Insofar the statement above and
the statement in MSDN would be insufficient.

Randy Webb

unread,
Aug 2, 2007, 4:47:56 AM8/2/07
to
Thomas 'PointedEars' Lahn said the following on 8/2/2007 3:45 AM:

> Randy Webb wrote:
>> Thomas 'PointedEars' Lahn said the following on 8/2/2007 3:14 AM:
>>> jidix...@gmail.com wrote:
>>>> <script language="JavaScript">
>>> <script type="text/javascript">
>> Deprecated.
>
> Don't be ridiculous.

How is me being right being "ridiculous" as the type="text/javascript"
MIME type was deprecated?

> You know very well that it is still the most
> widely supported media type for client-side
> scripting, no matter what the *informational*
> RFC4329 says.

My opinion of RFC's ranks right up there with my opinion of ECMAScript
and I don't think we need to go through that one again. Either way, the
type="text/javascript" MIME type is deprecated.

But, since you are defending it by saying it is the "most widely
supported" then why do you have a problem with 'window' being the Global
Object since it is the "most widely supported" Global Object in Web
Browsers?

You can't have it both ways.

Thomas 'PointedEars' Lahn

unread,
Aug 2, 2007, 5:01:31 AM8/2/07
to
Randy Webb wrote:
> Thomas 'PointedEars' Lahn said the following on 8/2/2007 3:45 AM:
>> Randy Webb wrote:
>>> Thomas 'PointedEars' Lahn said the following on 8/2/2007 3:14 AM:
>>>> jidix...@gmail.com wrote:
>>>>> <script language="JavaScript">
>>>> <script type="text/javascript">
>>> Deprecated.
>> Don't be ridiculous.
>
> How is me being right being "ridiculous" as the type="text/javascript"
> MIME type was deprecated?

Because you use the word here deliberately in the way (at least) I use
it -- as a means to tell that it is not wise to do so. You can't fool
me, and for that matter I think you can't fool anyone here that you are
simply trolling.

>> You know very well that it is still the most
>> widely supported media type for client-side
>> scripting, no matter what the *informational*
>> RFC4329 says.
>

> [...] since you are defending [type="text/javascript"] by saying it is


> the "most widely supported" then why do you have a problem with 'window'
> being the Global Object since it is the "most widely supported"
> Global Object in Web Browsers?
>
> You can't have it both ways.

Yes, I can. The fact aside that it is not the Global Object, but merely
happens to have most of its properties in common with it in some
browsers, for `window' as a reference for/to the Global Object there is
a viable standards compliant alternative. For type="text/javascript"
there is NOT at the time of writing.

Randy Webb

unread,
Aug 2, 2007, 6:01:05 AM8/2/07
to
Thomas 'PointedEars' Lahn said the following on 8/2/2007 5:01 AM:

> Randy Webb wrote:
>> Thomas 'PointedEars' Lahn said the following on 8/2/2007 3:45 AM:
>>> Randy Webb wrote:
>>>> Thomas 'PointedEars' Lahn said the following on 8/2/2007 3:14 AM:
>>>>> jidix...@gmail.com wrote:
>>>>>> <script language="JavaScript">
>>>>> <script type="text/javascript">
>>>> Deprecated.
>>> Don't be ridiculous.
>> How is me being right being "ridiculous" as the type="text/javascript"
>> MIME type was deprecated?
>
> Because you use the word here deliberately in the way (at least) I use
> it -- as a means to tell that it is not wise to do so.

Nice to see you know so much about what I mean. Even if I used the wrong
word. It is not deprecated, it is obsolete.

<URL: http://www.rfc-editor.org/rfc/rfc4329.txt>

<quote cite="http://en.wikipedia.org/wiki/Obsolete">
Obsolescence is the state of being which occurs when a person, object,
or service is no longer wanted even though it may still be in good
working order.
</quote>

> You can't fool me, and for that matter I think you can't fool
> anyone here that you are simply trolling.

Now there is the Thomas I was waiting on. When someone won't back down
from you (because they are right), you call them a troll. When does your
schooling begin back? It was peaceful around here for a while.

<snip>

dhtmlk...@gmail.com

unread,
Aug 2, 2007, 1:08:59 PM8/2/07
to

Almost!

document.getElementById("spp").name = "a";

That will do it.

Well, IE will sometimes return an array for getElementById, and even
conflate the DOM ID tree with named elements without IDs.

0 new messages