473,783 Members | 2,516 Online
Bytes | Software Development & Data Engineering Community
+ 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.crea teElement('tr') ;
var c=document.crea teElement('td') ;
var cn=c.cloneNode( false);
cn.className='t dname'; cn.appendChild( document.create TextNode(p));
var c2=c.cloneNode( false);
var i=document.crea teElement('inpu t');
i.type='text'; i.size=8; i.className='it ext';
var i2=i.cloneNode( true); i.name=p+'pas'; i2.name=p+'fun' ;
c.appendChild(i );
c2.appendChild( i2);
r.appendChild(c n);
r.appendChild(c );
r.appendChild(c 2);
var x=document.getE lementsByTagNam e('table')[0].rows;
x=x[x.length-1]; // the one before the last
x.parentNode.in sertBefore(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 2179


Ivo wrote:
I have this code to add a row to a table:

var r=document.crea teElement('tr') ;
var c=document.crea teElement('td') ;
var cn=c.cloneNode( false);
cn.className='t dname'; cn.appendChild( document.create TextNode(p));
var c2=c.cloneNode( false);
var i=document.crea teElement('inpu t');
i.type='text'; i.size=8; i.className='it ext';
var i2=i.cloneNode( true); i.name=p+'pas'; i2.name=p+'fun' ;
c.appendChild(i );
c2.appendChild( i2);
r.appendChild(c n);
r.appendChild(c );
r.appendChild(c 2);
var x=document.getE lementsByTagNam e('table')[0].rows;
x=x[x.length-1]; // the one before the last
x.parentNode.in sertBefore(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.create Element('<input type="text" name="inputName ">')

--

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

Jul 23 '05 #2
Ivo
"Martin Honnen" wrote
Ivo wrote:
var i=document.crea teElement('inpu t');
i.type='text'; i.size=8; i.className='it ext';
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.a sp which indicates there are problems with the name attribute and
unfortunately suggests you need to use the IE only extension
document.create Element('<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
5198
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 calculate the totals in each row. when i try however, i receive the error: "Error: 'elements' is null or not an object"
2
42873
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. e.g. aTextBox=document.createElement('input'); aTextBox.onchange=calculateOneRow2;
2
2693
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 the information is passed correctly. I am now trying to validate the form using JavaScript when the page is submitted. Firefox has no problems with this but IE returns 'document.form1.*THE FORM FIELD*.value is null or not an object' for the...
4
4285
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"); tmp.setAttribute("name", "tmpdiv2"); tmp.setAttribute("id", "calendar"); var image = document.createElement("img"); image.setAttribute("src", "img/ok.gif");
3
2199
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 Page_Load(ByVal obj As Object, ByVal ea As EventArgs) Dim xmlDoc As New XmlDocument() xmlDoc.Load(Server.MapPath("AppendData.xml")) Dim eltProducts1 As XmlElement = xmlDoc.CreateElement("Products")
3
4011
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 with a createElement function to add additional entries. The table has the first row of input text boxes already in it. You have to click a button to add another row. That seems to be working fine. How do I pull the information from the input boxes...
7
2526
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 Opera: var myfl_div = document.createElement('myfldiv'); myfl_div.setAttribute('style','position:absolute; left:100px; top:200px; width:960px; height: 560px; background-color: transparent;z-index: 5;'); function myFl_obj_emb() {
7
1841
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>                 <td><span class="obligatory">Offer type</span>:</td>                 <td>                         <select name="offer_type" onchange="ShowAnnouncementRows();">
23
6633
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 use it? IE5 or IE6? Thanks
0
9480
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
10315
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...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9946
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...
1
7494
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
5379
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.