473,605 Members | 2,590 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.create Element('<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 11226
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.create Element('<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.create Element('p');
p.appendChild(d ocument.createT extNode('IE Sucks!'));
p.name = 'IE';
document.getEle mentsByTagName( 'body')[0].appendChild(p) ;
}

<p onclick="alert( document.getEle mentsByTagName( '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.create Element('<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 "programmin g 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
programmaticall y, it is this name that changes, not the "programmin g
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.n ameIset

or

document.form.e lements['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
2169
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'; cn.appendChild(document.createTextNode(p)); var c2=c.cloneNode(false); var i=document.createElement('input'); i.type='text'; i.size=8; i.className='itext'; var i2=i.cloneNode(true); i.name=p+'pas'; i2.name=p+'fun';
6
1459
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 = document.createElement('IMG'); img.src = file; img.myProperty = 'myValue';
7
4841
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+ doesn't seem to have the problem. I'm doing: this.iframe = document.createElement( 'iframe' ); this.iframe.id = this.id + 'wh'; this.iframe.style.display = 'none';
7
5276
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 (Mozilla is fine). I don't get an error message but if I try to address this button by its name e.g. document.getElementsByName("MyButton").style.visibility = "hidden" I get with the Internet Explorer (Mozilla works fine) the following error message:
5
2862
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 elements in the form, including those that are added dynamically. I use document.getElementsByName('Field Name')to achieve the same.
16
3513
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 and then query for the root element, the result is always null (1). However if I strip the root element of all attributes generated by XmlSpy, then there is no problem to find the root element with .NET XML classes (2). (1) The XML for which...
6
1892
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> <Elements> <Element att1="1" att2="2" att3="3" //Some attributes are
3
1709
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 form i add an entry to the tree view when i save it another process is started "part of which is an encryption scheme" the important part i need help with is saving the sharedkey as the value of the elements parent tag applied to a new addition to the...
4
1868
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 System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing;
0
7934
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8425
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8071
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8288
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6743
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5886
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5445
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2438
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1541
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.