Connecting Tech Pros Worldwide Help | Site Map

Deleting cells by name instead of index?

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 23rd, 2005, 11:24 AM
Rich Morey
Guest
 
Posts: n/a
Default Deleting cells by name instead of index?

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

  #2  
Old July 23rd, 2005, 11:25 AM
Tim Williams
Guest
 
Posts: n/a
Default Re: Deleting cells by name instead of index?

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@27east.com> wrote in message
news:f69a1b96.0406050842.3156a444@posting.google.c om...[color=blue]
> Hi,
>
> I have a table where I am altering the layout via javascript to[/color]
create[color=blue]
> 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[/color]
are[color=blue]
> 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[/color]


  #3  
Old July 23rd, 2005, 11:26 AM
Rich Morey
Guest
 
Posts: n/a
Default Re: Deleting cells by name instead of index?

"Tim Williams" <saxifraxREMOVE@THISpacbell.net> wrote in message news:<2vxwc.80511$hG7.27078@newssvr25.news.prodigy .com>...[color=blue]
> 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
>
>[/color]

No, but I will..

Thanks for the idea..

Rich
  #4  
Old July 23rd, 2005, 11:26 AM
Rich Morey
Guest
 
Posts: n/a
Default Re: Deleting cells by name instead of index?

"Tim Williams" <saxifraxREMOVE@THISpacbell.net> wrote in message news:<2vxwc.80511$hG7.27078@newssvr25.news.prodigy .com>...[color=blue]
> 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[/color]


That worked!!! Thanks sooo much!!

:-)

Rich
  #5  
Old July 23rd, 2005, 11:26 AM
Rich Morey
Guest
 
Posts: n/a
Default Re: Deleting cells by name instead of index?

"Tim Williams" <saxifraxREMOVE@THISpacbell.net> wrote in message news:<2vxwc.80511$hG7.27078@newssvr25.news.prodigy .com>...[color=blue]
> 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();
>[/color]

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
  #6  
Old July 23rd, 2005, 11:26 AM
Lasse Reichstein Nielsen
Guest
 
Posts: n/a
Default Re: Deleting cells by name instead of index?

rwmorey@27east.com (Rich Morey) writes:
[color=blue]
> 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.[/color]

Then use:
---
var cell = document.getElementById('r2c8');
cell.parentElement.deleteCell(cell.cellIndex);
---

/L
--
Lasse Reichstein Nielsen - lrn@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
  #7  
Old July 23rd, 2005, 11:27 AM
Rich Morey
Guest
 
Posts: n/a
Default Re: Deleting cells by name instead of index?

>[color=blue]
> Then use:
> ---
> var cell = document.getElementById('r2c8');
> cell.parentElement.deleteCell(cell.cellIndex);
> ---[/color]

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
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.