HighDots Forums  

Deleting cells by name instead of index?

Javascript JavaScript language (comp.lang.javascript)


Discuss Deleting cells by name instead of index? in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Rich Morey
 
Posts: n/a

Default Deleting cells by name instead of index? - 06-05-2004 , 12:42 PM






Hi,

I have a table where I am altering the layout via javascript to create
colspans. I want to then delete the "Extra" cells created by the
colspans.

I have named the cells "r1c1", "r1c2", "r2c1", etc..

document.getElementById('r2c2').colSpan="4"
cellRows = document.getElementById('tableChart').rows(1);
cellRows.deleteCell(2);
cellRows.deleteCell(2);
cellRows.deleteCell(2);

document.getElementById('r2c7').colSpan="4"
cellRows = document.getElementById('tableChart').rows(1);
cellRows.deleteCell(4);
cellRows.deleteCell(4);
cellRows.deleteCell(4);

This code works because when I'm working on r2c7, I know that I've
already deleted three cells above and so the next cells to delete are
column index of 4.. but what I'd like to be able to do is delete the
cells by name, in this case
'r2c8', 'r2c9', and 'r2c10'

Is there anyway to do that? I tried just

document.getElementById('r2c8').deleteCell()

but that gave me a javascript error..

Thanks,

Rich

Reply With Quote
  #2  
Old   
Tim Williams
 
Posts: n/a

Default Re: Deleting cells by name instead of index? - 06-06-2004 , 12:57 AM






not certain but it seems as though deleteCell() may be a method of a
*row* object so have you tried

document.getElementById('r2c8').parentElement.dele teCell();

Tim



"Rich Morey" <rwmorey (AT) 27east (DOT) com> wrote

Quote:
Hi,

I have a table where I am altering the layout via javascript to
create
colspans. I want to then delete the "Extra" cells created by the
colspans.

I have named the cells "r1c1", "r1c2", "r2c1", etc..

document.getElementById('r2c2').colSpan="4"
cellRows = document.getElementById('tableChart').rows(1);
cellRows.deleteCell(2);
cellRows.deleteCell(2);
cellRows.deleteCell(2);

document.getElementById('r2c7').colSpan="4"
cellRows = document.getElementById('tableChart').rows(1);
cellRows.deleteCell(4);
cellRows.deleteCell(4);
cellRows.deleteCell(4);

This code works because when I'm working on r2c7, I know that I've
already deleted three cells above and so the next cells to delete
are
column index of 4.. but what I'd like to be able to do is delete the
cells by name, in this case
'r2c8', 'r2c9', and 'r2c10'

Is there anyway to do that? I tried just

document.getElementById('r2c8').deleteCell()

but that gave me a javascript error..

Thanks,

Rich



Reply With Quote
  #3  
Old   
Rich Morey
 
Posts: n/a

Default Re: Deleting cells by name instead of index? - 06-07-2004 , 11:09 AM



"Tim Williams" <saxifraxREMOVE (AT) THISpacbell (DOT) net> wrote

Quote:
not certain but it seems as though deleteCell() may be a method of a
*row* object so have you tried

document.getElementById('r2c8').parentElement.dele teCell();

Tim


No, but I will..

Thanks for the idea..

Rich


Reply With Quote
  #4  
Old   
Rich Morey
 
Posts: n/a

Default Re: Deleting cells by name instead of index? - 06-07-2004 , 11:12 AM



"Tim Williams" <saxifraxREMOVE (AT) THISpacbell (DOT) net> wrote

Quote:
not certain but it seems as though deleteCell() may be a method of a
*row* object so have you tried

document.getElementById('r2c8').parentElement.dele teCell();

Tim

That worked!!! Thanks sooo much!!

:-)

Rich


Reply With Quote
  #5  
Old   
Rich Morey
 
Posts: n/a

Default Re: Deleting cells by name instead of index? - 06-07-2004 , 11:16 AM



"Tim Williams" <saxifraxREMOVE (AT) THISpacbell (DOT) net> wrote

Quote:
not certain but it seems as though deleteCell() may be a method of a
*row* object so have you tried

document.getElementById('r2c8').parentElement.dele teCell();

Okay, scratch that.. it didn't work.. Its just deleting the last cell
in the row, because the parent element of the cell is the row and
calling the deleteCell() without a variable deletes the last cell in
the row.

Rich


Reply With Quote
  #6  
Old   
Lasse Reichstein Nielsen
 
Posts: n/a

Default Re: Deleting cells by name instead of index? - 06-07-2004 , 01:44 PM



rwmorey (AT) 27east (DOT) com (Rich Morey) writes:

Quote:
Okay, scratch that.. it didn't work.. Its just deleting the last cell
in the row, because the parent element of the cell is the row and
calling the deleteCell() without a variable deletes the last cell in
the row.
Then use:
---
var cell = document.getElementById('r2c8');
cell.parentElement.deleteCell(cell.cellIndex);
---

/L
--
Lasse Reichstein Nielsen - lrn (AT) hotpop (DOT) com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'


Reply With Quote
  #7  
Old   
Rich Morey
 
Posts: n/a

Default Re: Deleting cells by name instead of index? - 06-07-2004 , 10:50 PM



Quote:
Then use:
---
var cell = document.getElementById('r2c8');
cell.parentElement.deleteCell(cell.cellIndex);
---
Okay, I will give that a try.. I did actually write my own function to
get the index of the cell in the array of cells in the row element.. I
did not know that the cellIndex function exsisted!

Rich


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.