473,410 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

Cloning rows works -- how to alter cells?

I'm able to clone a table row using this:

function insert(btn) {var cell, newRow, row, sect;
if((cell = btn.parentNode) && (row = cell.parentNode) &&
row.cloneNode && (sect = row.parentNode) && sect.insertBefore)
{
newRow = row.cloneNode(true);
/* If you need to alter the new row
* or its contents, do it here.
*/

sect.insertBefore(newRow, row.nextSibling);
}
}

the problem is that I need to change contents of 2 cells. One cell
contains an input box that should be blank in the new row, one cell
contains an input box that shoule be reset to 1 in the new row. The
script indicates that I can 'alter the new row', but how do I access
the cell contents to make changes?

Also, the button to add rows is in the last column of the row. Is
there a way to remove (or hide) it in all but the last row?

Thanks,
Rich

Aug 6 '06 #1
7 3386


Rich_C wrote:

newRow = row.cloneNode(true);
the problem is that I need to change contents of 2 cells. One cell
contains an input box that should be blank in the new row, one cell
contains an input box that shoule be reset to 1 in the new row. The
script indicates that I can 'alter the new row', but how do I access
the cell contents to make changes?
The row element object has a cells collection so you can access e.g.
newRow.cells
newRow.cells.length
newRow.cells[0] // first cell
and then if you access a cell you have the DOM with childNodes, with
getElementsByTagName to access stuff in the cell.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 6 '06 #2
Thanks Martin --
I'm getting 'cells.4' is null or not an object in IE when I try

newRow.cells[4].getElementsByTagName('input')[0].value =1;

any idea what's not right?


Martin Honnen wrote:
Rich_C wrote:

newRow = row.cloneNode(true);
the problem is that I need to change contents of 2 cells. One cell
contains an input box that should be blank in the new row, one cell
contains an input box that shoule be reset to 1 in the new row. The
script indicates that I can 'alter the new row', but how do I access
the cell contents to make changes?

The row element object has a cells collection so you can access e.g.
newRow.cells
newRow.cells.length
newRow.cells[0] // first cell
and then if you access a cell you have the DOM with childNodes, with
getElementsByTagName to access stuff in the cell.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 6 '06 #3


Rich_C wrote:

I'm getting 'cells.4' is null or not an object in IE when I try

newRow.cells[4].getElementsByTagName('input')[0].value =1;
Well what is newRow.cells.length? Are there at least 5 cells? The index
starts with 0 so the first cell is newRow.cells[0].
--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 6 '06 #4
there are 16 cells

Martin Honnen wrote:
Rich_C wrote:

I'm getting 'cells.4' is null or not an object in IE when I try

newRow.cells[4].getElementsByTagName('input')[0].value =1;

Well what is newRow.cells.length? Are there at least 5 cells? The index
starts with 0 so the first cell is newRow.cells[0].
--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 6 '06 #5


Rich_C wrote:
there are 16 cells
Can you post a URL where the error occurs?
What happens if you try the script with other browsers, does that work
or do you get an error too?
--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 6 '06 #6
It's an intranet site, so no public access.

it works in Netscape, but causes other things to break on this page and
throughout the site. We wrote for IE only since it's written for
internal users and we can specifiy the browser.
Martin Honnen wrote:
Rich_C wrote:
there are 16 cells

Can you post a URL where the error occurs?
What happens if you try the script with other browsers, does that work
or do you get an error too?
--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 6 '06 #7
Martin,

Finally got this to work.. thanks for all your help!

apparently IE won't allow a change until after it's been written. I
switched these two lines and it works perfectly.

sect.insertBefore(newRow, row.nextSibling);

newRow.cells[4].getElementsByTagName("input")[0].value = 1;
Rich_C wrote:
It's an intranet site, so no public access.

it works in Netscape, but causes other things to break on this page and
throughout the site. We wrote for IE only since it's written for
internal users and we can specifiy the browser.
Martin Honnen wrote:
Rich_C wrote:
there are 16 cells
Can you post a URL where the error occurs?
What happens if you try the script with other browsers, does that work
or do you get an error too?
--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 8 '06 #8

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

Similar topics

12
by: Rick DeBay | last post by:
I'm trying to create a layout table, where the spacing between rows varies. I've tried using setting margin-top and border-top for the rows I wan't spaced down from the one above, and I've also...
3
by: dotNetDave | last post by:
I have some xml that I am loading into a DataSet. Later in my program I have to clone that DataSet but I keep getting an error saying that I can't have a table named the same as my DataSet?!? If...
3
by: foldface | last post by:
Hi This works but is a bit long-winded. Is there a better way? ta F <style> ..Header { background-color: gray;
7
by: sonic | last post by:
Hello, I am cloning a table row which contains images that have behaviors attached to them as well as onclick events. The problem is that the cloned row seems to be executing the...
6
by: jhallbox | last post by:
I am unclear how to test this object I'm sending to my function. It is a cell in a table and I simply want to know which row it is in. I am not a javascript programmer but a javascript cobbler, so...
1
by: martin | last post by:
Hi, I have a datagrid that contains 3 colums. This is rendered to the page fine, except that I would like to be able to control the width of each table cell of the datagrid I have the following...
2
by: e271828 | last post by:
Is there a way to specify more than one row or cell collection in the JS table object? Consider this: var x=document.getElementById('myTable').rows.cells x.innerHTML="NEW CONTENT" This...
4
by: lord.zoltar | last post by:
I am wondering how you guys highlight cells or rows (by changing the text or background colour) in a DataGridView. Right now, I apply styles to certain rows or cells in the CellFormatting even...
1
by: samn | last post by:
I wrote the following script in order to traverse an HTML table and merge the cells that have the same value across multiple rows. For some reason, however, it works for the first, third, and...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...
0
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...
0
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
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...
0
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...

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.