473,473 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

createElement with a name

Ivo
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';
c.appendChild(i);
c2.appendChild(i2);
r.appendChild(cn);
r.appendChild(c);
r.appendChild(c2);
var x=document.getElementsByTagName('table')[0].rows;
x=x[x.length-1]; // the one before the last
x.parentNode.insertBefore(r,x);

I 'm sure I 'm missing something obvious, the row is added correctly,
containing the expected cells each with the right input elements, but the
generated input elements don't have names. It is the same with inputs of
type checkbox. The classes are set correctly, but [element].name returns
undefined. Howcome and what can I do about it?
Thanks
Ivo
Jul 23 '05 #1
2 2159


Ivo wrote:
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';
c.appendChild(i);
c2.appendChild(i2);
r.appendChild(cn);
r.appendChild(c);
r.appendChild(c2);
var x=document.getElementsByTagName('table')[0].rows;
x=x[x.length-1]; // the one before the last
x.parentNode.insertBefore(r,x);

I 'm sure I 'm missing something obvious, the row is added correctly,
containing the expected cells each with the right input elements, but the
generated input elements don't have names. It is the same with inputs of
type checkbox. The classes are set correctly, but [element].name returns
undefined. Howcome and what can I do about it?


If you have problems with a script and come here please tell us which
browser or browsers that problem occurs with.
And above I don't see where you test the name property, please show
when/where you are doing that.
IE has a documented restriction, see
http://msdn.microsoft.com/library/de...ateelement.asp
which indicates there are problems with the name attribute and
unfortunately suggests you need to use the IE only extension
document.createElement('<input type="text" name="inputName">')

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #2
Ivo
"Martin Honnen" wrote
Ivo wrote:
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';

generated input elements don't have names. It is the same with inputs of
type checkbox. The classes are set correctly, but [element].name returns
undefined. Howcome and what can I do about it?
If you have problems with a script and come here please tell us which
browser or browsers that problem occurs with.


Yes sorry, I forgot. Testing in IE6/Win only sofar. Ultimately it should run
on IE/Mac as well...
And above I don't see where you test the name property, please show
when/where you are doing that.
There is no explicit test in the code as shown. It is a stripped down
version of a much larger script.
IE has a documented restriction, see
http://msdn.microsoft.com/library/de...thor/dhtml/ref
erence/methods/createelement.asp which indicates there are problems with the name attribute and
unfortunately suggests you need to use the IE only extension
document.createElement('<input type="text" name="inputName">')


I see. Shucks. That is a helpful link.
Thanks
Ivo
Jul 23 '05 #3

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

Similar topics

25
by: kie | last post by:
hello, i have a table that creates and deletes rows dynamically using createElement, appendChild, removeChild. when i have added the required amount of rows and input my data, i would like to...
2
by: kie | last post by:
hello, when i create elements and want to assign events to them, i have realised that if the function assigned to that element has no parameters, then the parent node values can be attained. ...
2
by: Dave | last post by:
I have a page which uses JavaScript to create form elements using document.createElement('input'), etc.. Both Firefox and IE have no problem accomplishing this and when the form is submitted all...
4
by: sg_maat | last post by:
I have a little problem with createElement(and msie). I was experimenting a bit with createElement and made the following script: <script> var tmp = document.createElement("div");...
3
by: Arpan | last post by:
Using DOM, this is how I am appending data to an existing XML file which is named AppendData.xml (the root element of AppendData.xml is <ProductList>): <script runat="server"> Sub...
3
by: acecraig100 | last post by:
I am fairly new to Javascript. I have a form that users fill out to enter an animal to exhibit at a fair. Because we have no way of knowing, how many animals a user may enter, I created a table...
7
by: Tarik Monem | last post by:
Why am I having so much trouble with using DOM in IE & Opera to create, then remove an Object & Embedded element? Here's the code that works in Firefox (Mac/Win/Linux) and Safari, but not on IE or...
7
by: r_ahimsa_m | last post by:
Hello, I am learning JavaScript. I have a table on HTML page:                 <table id="announcement_fields" border="0">                 <tbody>                 <tr>...
23
by: vunet | last post by:
It is recommended by some sources I found to create IFrames in IE using document.createElement('<iframe src="#">') instead of document.createElement('iframe'). Why and what browser versions to...
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
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,...
1
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...
0
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,...
1
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...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.