By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 2,023 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 IT Pros & Developers. It's quick & easy.

createElement with a name

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a


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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.