469,318 Members | 1,937 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

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

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Ivo | last post: by
6 posts views Thread by Martin | last post: by
7 posts views Thread by Christopher J. Hahn | last post: by
7 posts views Thread by Stefan Mueller | last post: by
16 posts views Thread by TT (Tom Tempelaere) | last post: by
6 posts views Thread by Jakub.Bednarczuk | last post: by
4 posts views Thread by =?Utf-8?B?VG9yZW4gVmFsb25l?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.