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

J

jidixuelang

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>


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>
 
J

jamie.ly

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>

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>

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

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

jidixuelang

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>

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>




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>





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

jidixuelang

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>
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>

If we were to just correct what you did, change the one line 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!
 
T

Thomas 'PointedEars' Lahn

Randy said:
<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
 
T

Thomas 'PointedEars' Lahn

<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????

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
 
T

Thomas 'PointedEars' Lahn

Randy said:
Thomas 'PointedEars' Lahn said the following on 8/2/2007 3:06 AM:
Randy said:
<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.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Randy said:
Thomas 'PointedEars' Lahn said the following on 8/2/2007 3:14 AM:

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.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Randy said:
Thomas 'PointedEars' Lahn said the following on 8/2/2007 3:45 AM:

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.


PointedEars
 
D

dhtmlkitchen

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>
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>

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

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

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top