Connecting Tech Pros Worldwide Help | Site Map

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

  #1  
Old June 7th, 2007, 09:45 PM
Walton
Guest
 
Posts: n/a
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?

  #2  
Old June 7th, 2007, 10:05 PM
-Lost
Guest
 
Posts: n/a

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


Walton wrote:
Quote:
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.
  #3  
Old June 8th, 2007, 09:15 AM
RobG
Guest
 
Posts: n/a

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


Walton wrote:
Quote:
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
  #4  
Old June 8th, 2007, 02:25 PM
Walton
Guest
 
Posts: n/a

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


Quote:
Does this not work in Internet Explorer 7? If so, they regressed.
yeah, i was using ie7. didn't test in ie6

  #5  
Old June 8th, 2007, 02:35 PM
Walton
Guest
 
Posts: n/a

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


On Jun 8, 8:22 am, Walton <jrhol...@gmail.comwrote:
Quote:
Quote:
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.

Closed Thread