473,408 Members | 1,763 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,408 software developers and data experts.

Help please !! Get th table id from the Row Id

I'm working on an existing project.

I've got a Row Id and I must find the table id (the table who contains the
row).

Is it possible ?

In fact, from a Row Id I must delete the row but I don't know the name or
the table Id.

Please help,

Stan
Jul 20 '05 #1
5 13755
Stanislas wrote:
I'm working on an existing project.

I've got a Row Id and I must find the table id (the table who contains the
row).

Is it possible ?

In fact, from a Row Id I must delete the row but I don't know the name or
the table Id.

Please help,

Stan


I dont think there is a direct way, but you can traverse the DOM tree.

A row must have a parent, grandparent, etc that is of type TABLE. So
you do something like this (pseudocode) :

function find_owning_table( row )
{
current_node = row;
while(current_node.parentNode.nodeName != "TABLE")
current_node = current_row.parentNode;

return current_row.parentNode;
}

Brian

Jul 20 '05 #2
On Wed, 21 Jan 2004 19:31:38 +0100, Stanislas <sr******@intertek.fr> wrote:
I've got a Row Id and I must find the table id (the table who contains
the
row).

Is it possible ?
Using the DOM, yes.

var tableRow = document.getElementById( 'rowID' );
// The first parent node points to the TBODY that contains the row.
// Even if one wasn't explicitly added, a TBODY element will be
// added implicitly
var table = tableRow.parentNode.parentNode;

This gives you references to the table row, and its containing table.
In fact, from a Row Id I must delete the row but I don't know the name or
the table Id.


Using the results above, this will delete the row:

table.deleteRow( tableRow.rowIndex );

If you aren't going to use the table reference for any other purpose, you
could make this slightly more efficient.

var tableRow = document.getElementById( 'rowID' );
tableRow.parentNode.deleteRow( tableRow.sectionRowIndex );

Don't forget that you should for support of the properties and methods
accessed.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #3
Michael Winter wrote:
On Wed, 21 Jan 2004 19:31:38 +0100, Stanislas <sr******@intertek.fr> wrote:
I've got a Row Id and I must find the table id (the table who contains
the
row).

Is it possible ?

Using the DOM, yes.

var tableRow = document.getElementById( 'rowID' );
// The first parent node points to the TBODY that contains the row.
// Even if one wasn't explicitly added, a TBODY element will be
// added implicitly
var table = tableRow.parentNode.parentNode;


Hmmmm... Is this a safe assumption? Do all DOM-compliant browsers do it
this way? What if it does not implicityly add a TBODY? I think a more
save approach is to traverse upwards, until you find the TABLE tag...
(like I mentioned in my earlier post)

What do you think?
Brian

Jul 20 '05 #4
On Wed, 21 Jan 2004 14:39:48 -0500, Brian Genisio
<Br**********@yahoo.com> wrote:
Hmmmm... Is this a safe assumption? Do all DOM-compliant browsers do it
this way? What if it does not implicityly add a TBODY?
If it does or not would depend on the doctype, I agree I wouldn't rely
on it. (and if you're of the opinion that compatilbility with XHTML
user agents is relevant you can guarantee they won't.)
I think a more
save approach is to traverse upwards, until you find the TABLE tag...
(like I mentioned in my earlier post)


Makes sense to me!

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #5
On Wed, 21 Jan 2004 14:39:48 -0500, Brian Genisio <Br**********@yahoo.com>
wrote:
Michael Winter wrote:


<snip>
var tableRow = document.getElementById( 'rowID' );
// The first parent node points to the TBODY that contains the row.
// Even if one wasn't explicitly added, a TBODY element will be
// added implicitly
var table = tableRow.parentNode.parentNode;


Hmmmm... Is this a safe assumption? Do all DOM-compliant browsers do it
this way? What if it does not implicityly add a TBODY? I think a more
save approach is to traverse upwards, until you find the TABLE tag...
(like I mentioned in my earlier post)

What do you think?


Technically, yes. The DTD description of the table requires that at least
one TBODY element must be present inside a table. If there is only one
body, the user may omit the actual tag, but the TBODY is still there.
However, I guess there aren't really any guarantees.

You wouldn't need to traverse far, anyway. The table node will either be
the first parent node, if TBODY is omitted, or the second, if it isn't.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #6

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

Similar topics

2
by: Ben | last post by:
The page below isn't picking up details or location. What have I missed? Thanks in advance, Ben ____________________________________________ <?PHP
3
by: laurie | last post by:
Hi all, I'm trying to help out a friend who has inherited a client with a PHP shopping cart application. Neither of us know PHP, but I've been muddling my way through, trying to get these old...
1
by: HolaGoogle | last post by:
Hi all, Please help me with the following..it's realy urgent and i tried everything i could and i can't get it work properly!! Thanks in advance. Here's what i'm trying to accomplish: in my...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
5
by: Craig Keightley | last post by:
Please help, i have attached my page which worksin IE but i cannnot get the drop down menu to fucntion in firefox. Any one have any ideas why? Many Thanks Craig ...
23
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application...
1
by: Usman Ghani | last post by:
Hi All, Please help me to develop this one page please. I have a page on which I have a label control, just one label with no text. Next I start a loop to read the headers of emails and during...
6
by: jenipriya | last post by:
Hi all... its very urgent.. please........i m a beginner in oracle.... Anyone please help me wit dese codes i hv tried... and correct the errors... The table structures i hav Employee (EmpID,...
1
by: lilbit02 | last post by:
Hi, I have a form that utilizes validation as most do via javascript. This form worked totaly fine until I needed to add a dynamic div now the validation doesn't work. It does work for the first...
1
by: deepaks85 | last post by:
Dear All, I want to send some data through a form with Multiple attachment in an HTML Format. I have tried it but it is not working for me. I am able to send data without attachment but with the...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...

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.