473,785 Members | 2,449 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I find the name of the parent table from a table cell?

I have something like this:

<table name="test" id="test">
<tr>
<td><input type="button" onClick="showMe ParentTableName ();"></td>
</tr>
</table>
How can I have my input button show me the table of it's parent table?
(eg. "test" in this case)

Jul 23 '05 #1
8 20220
err, I mean... how can I have the button show me the NAME of it's
parent table.

Jul 23 '05 #2
try this;

<table name="test" id="test">
<tr>
<td><input type="button"
onClick="showMe ParentTableName (this);"></td>
</tr>
</table>

<script>
function showMeParentTab leName(oInput){
this.value =
this.parentNode .parentNode.par entNode.parentN ode.name;
}
</script>

notice that you must go up 4 levels in the object hierarchy;

input -> cell -> row -> tablebody -> table

this only applies to IE, firefox needs one less step up.

Jul 23 '05 #3
jk*****@gmail.c om wrote:


How can I have my input button show me the table of it's parent table?
(eg. "test" in this case)

....
<td><input type="button" onClick="climbT o(this,'table') "></td>
....

<script type="text/javascript">
function climbTo(element ,tagname){
var pa=element.pare ntNode;
while(pa.tagNam e.toLowerCase() !=tagname.toLow erCase()){
pa=pa.parentNod e;
}
alert(pa.name)
}
</script>

Mick
Jul 23 '05 #4
jk*****@gmail.c om wrote:
I have something like this:

<table name="test" id="test">
<tr>
<td><input type="button" onClick="showMe ParentTableName ();"></td>
</tr>
</table>
How can I have my input button show me the table of it's parent table?
(eg. "test" in this case)
"name" is not a valid attribute of an HTML table. Use id. Pass the
input object to the function.

<html>
<head>
<title>untitled </title>
<script type="text/javascript">

function getTableId(obj)
{
while (obj && !/table/i.test(obj.node Name))
{
obj = obj.parentNode;
}
return obj.id || '';
}

</script>
</head>
<body>
<table border="1" id="test1">
<tbody>
<tr>
<td>
<input
type="button"
value="test 1"
onclick="alert( getTableId(this ))">
</td>
</tr>
</tbody>
</table>
<table border="1" id="test2">
<tbody>
<tr>
<td>
<input
type="button"
value="test 2"
onclick="alert( getTableId(this ))">
</td>
</tr>
</tbody>
</table>
</body>
</html>
michael elias wrote: try this;
(snip)
function showMeParentTab leName(oInput){
this.value =
this.parentNode .parentNode.par entNode.parentN ode.name;
}
'this' in the context of a global function points to *window*.

notice that you must go up 4 levels in the object hierarchy;

input -> cell -> row -> tablebody -> table

this only applies to IE, firefox needs one less step up.


Any time you need to give involved instructions like the above, it's
time to use some program logic to *look for* the desired data.

Jul 23 '05 #5

All form elements, Inputs too, have a parent of Form, and form has other
parents and such, instead, use a link in the TD,
..parentElement .parentElement. parentElement of a link on the TD will be the
table, if you use an input, you'd have to go UP more parentElements passed
the Form and who knows what else you have the form in if any.

Danny

On Tue, 21 Jun 2005 07:50:58 -0700, <jk*****@gmail. com> wrote:

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 23 '05 #6
"Mick White" <mw***********@ rochester.rr.co m> wrote in message
news:r4******** **********@twis ter.nyroc.rr.co m...
jk*****@gmail.c om wrote:

How can I have my input button show me the table of it's parent
table?
(eg. "test" in this case)

...
<td><input type="button" onClick="climbT o(this,'table') "></td>
...

<script type="text/javascript">
function climbTo(element ,tagname){
var pa=element.pare ntNode;
while(pa.tagNam e.toLowerCase() !=tagname.toLow erCase()){
pa=pa.parentNod e;
}
alert(pa.name)
}
</script>


If this function can't find the tagName it's looking for, it eventually
generates an error:

<span id="blah"></span>
<script type="text/javascript">
function climbTo(element ,tagname){
var pa=element.pare ntNode;
while(pa.tagNam e.toLowerCase() !=tagname.toLow erCase()){
pa=pa.parentNod e;
}
alert(pa.name)
}
climbTo(documen t.getElementByI d('blah'), 'table');
</script>

Something like this might be better:

function climbTo(element , tagname) {
tagname = tagname.toLower Case();
var parentElement;
while((element = element.parentN ode) && !parentElement) {
if (element.tagNam e.toLowerCase() == tagname) {
parentElement = element;
}
}

// return parentElement;
if (parentElement) {
alert(parentEle ment.id);
}
}

--
Grant Wagner <gw*****@agrico reunited.com>
comp.lang.javas cript FAQ - http://jibbering.com/faq
Jul 23 '05 #7
Grant Wagner wrote:
If this function can't find the tagName it's looking for, it
eventually generates an error:
[...]
Something like this might be better:

function climbTo(element , tagname) {
tagname = tagname.toLower Case();
var parentElement;
while((element = element.parentN ode) && !parentElement) {
if (element.tagNam e.toLowerCase() == tagname) {
parentElement = element;
}
}

// return parentElement;
if (parentElement) {
alert(parentEle ment.id);
}
}


I'd prefer RegExps here:

function climbTo(element , tagname)
{
var rx = new RegExp(tagname, "i");
var parentElement;
while ((element = element.parentN ode) && !parentElement)
{
if (element.tagNam e.test(rx))
{
parentElement = element;
}
}

// return parentElement;
if (parentElement)
{
alert(parentEle ment.id);
}
}
PointedEars
Jul 23 '05 #8
Thomas 'PointedEars' Lahn <Po*********@we b.de> writes:
I'd prefer RegExps here:

function climbTo(element , tagname)
{
var rx = new RegExp(tagname, "i");
You should at least anchor the match, i.e.,
var rx = new RegExp("^"+tagn ame+"$", "i");

Otherwise tagnames that are substrings of other tag names can
give incorrect matches (which will probably not happen for valid
HTML, but might as well be safe).

.... if (element.tagNam e.test(rx))
{
parentElement = element;
} .... if (parentElement)


I'm not sure the original poster had thought this through enough for
it to be generalized. This code will find the outermost enclosing
element matching the tag name, not the innermost one. That might be
desired behavior in this case, but in general, I'd more likely be
needing the nearest enclosing element.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #9

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

Similar topics

0
2116
by: Mark Tait | last post by:
Hi - I think I'm getting very tied up here. Using Web Matrix, and have posted in the asp.net forum, with no help unfortunately. I have a table, which has a parent/child relationship with itself. It has an id, fldparentid, fldquestion field. I want to show the fields where the fldparentid is the same as the value returned when someone clicks on the ros in my datagrid, in the function: gridCategory_SelectedIndexChanged.
6
7680
by: chris | last post by:
is there a way by using html or javascript or anything else for that matter to detirmine the actual height or width of a table or cell for example if i only set the height to 100 and the data in the cell needs a higher cell it expands to suit - i want to find out what the actual height ends up ?? thanks for your help chris
4
5378
by: Amos | last post by:
I built the following Sub, in order to create tables automatically. The button is placed on a mask where there are 3 txt box, two of them contain the "Bank name" and "Bank a/c". I want to name the new table with a string composed by the "Bank name"&"Bank a/c", How I could get it? Using the following Sub I get always the same name "NEWBANKAC". Any Tip is welcome. Thank you.
4
1956
by: Filips Benoit | last post by:
Dear All, Is ( how) it possible to find the tablename of the table that is related to a field. Field CLIENT_TITLE_ID is related to table TITLE Thanks, Filip
1
1791
by: colleen1980 | last post by:
There is a form where it ask the two dates and then run a query then report. Private Sub Command36_Click() DoCmd.OpenQuery "qryResultsReport" DoCmd.OpenReport "rpt_TopTen", acPreview, "", "" end sub qryResultsReport
12
2246
by: Orchid | last post by:
Hello all, I have different version of reports which used for different months. For example, I am using report version 1 up to September, but we have some design changes on the report for October, so I created report version 2. I want a same Command Button to open the appropriated version report for the specific month. I create a table with the following Fields: Month, ReportID, ReportToOpen (this is the exact report name). On a form,...
10
3387
by: bhughes2187 | last post by:
Hey all, The access app I am creating, pulls a .dbf file into a table in access. The name of the printer to be printed to is contained in that file/table. How would I cycle through the list of printers on my pc until i matched the name in the table and then set the printer to that specific printer..? I am trying this code and it doesn't seem to work prntpdf = DLookup("printerpdf", "scarlet") 'Get printer name to print to 'Set...
2
2458
by: gm000 | last post by:
hi i m using radiobuttonlist with images like this <asp:RadioButtonList ID="rbtnthumb1" runat="server"> <asp:ListItem Value ="News_icon.jpg"> <img src="http://bytes.com/images/News_icon.jpg" alt="News" align="absmiddle"> News </asp:ListItem> <asp:ListItem Value ="imageicon.bmp"> <img src="http://bytes.com/images/imageicon.bmp" alt="Image" align="absmiddle">
4
2353
by: timleonard | last post by:
Is it possible and if so, how? Would like to have code to verify that a file name in a same directory matches with the file name in a table/ field. If it matches then run the rest of the code, if not prompt with error. Can someone give me some pointer how this should be written Thanks for any help you could offer
5
1311
by: eneyardi | last post by:
How to save the form name in a table (the form data source) I have table name: OD, form name: OD User1, In form OD User1 i have textboxes: Sender, Subject, From, To and Received by. thanks in advance..(,")
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10325
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
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
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
6739
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
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?
3
2879
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.