473,386 Members | 1,832 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,386 software developers and data experts.

IE cannot set 'name' attribute on runtime elements created by createElement

checkout: (3rd paragraph under 'Remarks' section)
http://msdn.microsoft.com/library/de...ies/name_2.asp

from the page:
"The NAME attribute cannot be set at run time on elements dynamically
created with the createElement method. To create an element with a
name attribute, include the attribute and value when using the
createElement method."

to work around this you have to code:

document.createElement('<div name="ieiscrap">')

which -surprise- fails in Firefox. i haven't tested in any other
browsers. this one really caused me a headache.

does anyone know why IE does this?

Jun 7 '07 #1
4 11215
Walton wrote:
checkout: (3rd paragraph under 'Remarks' section)
http://msdn.microsoft.com/library/de...ies/name_2.asp

from the page:
"The NAME attribute cannot be set at run time on elements dynamically
created with the createElement method. To create an element with a
name attribute, include the attribute and value when using the
createElement method."

to work around this you have to code:

document.createElement('<div name="ieiscrap">')

which -surprise- fails in Firefox. i haven't tested in any other
browsers. this one really caused me a headache.

does anyone know why IE does this?
window.onload = function()
{
var p = document.createElement('p');
p.appendChild(document.createTextNode('IE Sucks!'));
p.name = 'IE';
document.getElementsByTagName('body')[0].appendChild(p);
}

<p onclick="alert(document.getElementsByTagName('p')[1].name);">show me
the money, er... name</p>

Works in Internet Explorer 6 (and any DOM-compliant/aware browser or
viewing device).

Does this not work in Internet Explorer 7? If so, they regressed.

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
Jun 7 '07 #2
Walton wrote:
checkout: (3rd paragraph under 'Remarks' section)
http://msdn.microsoft.com/library/de...ies/name_2.asp

from the page:
"The NAME attribute cannot be set at run time on elements dynamically
created with the createElement method. To create an element with a
name attribute, include the attribute and value when using the
createElement method."

to work around this you have to code:

document.createElement('<div name="ieiscrap">')

which -surprise- fails in Firefox. i haven't tested in any other
browsers. this one really caused me a headache.

does anyone know why IE does this?
The key is in the paragraph above the one you referenced:

"Microsoft JScript allows the name to be changed at run time. This does
not cause the name in the programming model to change in the collection
of elements, but it does change the name used for submitting elements."

In other words, IE assigns a "programming model" name attribute when the
control is created and it can't be changed. However, controls seem to
also have a user definable name: if you change the name of the control
programmatically, it is this name that changes, not the "programming
model" name. If you submit the control with the form, the name that is
submitted is the programming model name or the (hidden) user-definable
name if it's been set. The name you set can't be used with the elements
collection, like:

document.form.nameIset

or

document.form.elements['nameIset']
Why is IE like that? Who knows, MS have only had 10 years to fix it,
maybe they like it like it is.
--
Rob
"We shall not cease from exploration, and the end of all our
exploring will be to arrive where we started and know the
place for the first time." -- T. S. Eliot
Jun 8 '07 #3
Does this not work in Internet Explorer 7? If so, they regressed.
yeah, i was using ie7. didn't test in ie6

Jun 8 '07 #4
On Jun 8, 8:22 am, Walton <jrhol...@gmail.comwrote:
Does this not work in Internet Explorer 7? If so, they regressed.

yeah, i was using ie7. didn't test in ie6
I should also be a bit clearer with my example. I was creating form
inputs and selects when running into this issue.

Jun 8 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ivo | last post by:
I have this code to add a row to a table: var r=document.createElement('tr'); var c=document.createElement('td'); var cn=c.cloneNode(false); cn.className='tdname';...
6
by: Martin | last post by:
I am having trouble trying to more closely relate objects (as functions) in javascript with HTML elements. For example, I have an object 'class' MyImage: function MyImage(file) { var img =...
7
by: Christopher J. Hahn | last post by:
I'm trying to use a script-generated form to submit to a script-generated iframe. The problem I'm running into is that the iframe is not assuming the name I assign it. IE6 on Win2000. FF1.0.2+...
7
by: Stefan Mueller | last post by:
How can I set the Name of a button? I tried xelement = document.createElement("input") xelement.type = "button" xelement.name = "MyButton" but it does not work with the Internet Explorer...
5
by: stellstarin | last post by:
I have a html where fields are created and added dynamically on the client side. I use the AppendChild() call to create fields dynamically. On submit i try to get the value for all the...
16
by: TT (Tom Tempelaere) | last post by:
Hi all, I created an XSD to define the structure of an XML file for my project. I made an XML file linked to the XSD using XmlSpy. The problem is that if I read the file using .NET XmlDocument...
6
by: Jakub.Bednarczuk | last post by:
Hallo everybody I have the problem with getting attributes values and also attributes names. I am reading an xml file with DOM. Lets see an example: file I read <root> <Def></Def>...
3
by: deaddog4201 | last post by:
How can i save a .txt file where the name of the file would be the result of the selection made from a Dom tree view's parent node tag in visual basic? So for example i have an editable tree view...
4
by: =?Utf-8?B?VG9yZW4gVmFsb25l?= | last post by:
Was editing code, am getting the following errors } expected Type or namespace definition, or end-of-file expected Eyes crossed cannot find code below! using System; using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.