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

Referencing enclosing table

Hi:

Is it possible to reference a table which contains a select list that
has an event handler that modifies the table, without using the table
ID?

Example: <table id="SearchTable">
event handler in select list is
onChange="addTableRow('SearchTable')"
And in addTableRow(), I have the following code:
var tbl = document.getElementById(which);
// etc, etc, works fine BUT, is
// there a component of the DOM that allows me to reference
// the table as a parent?

If so, pointers and URLs to appropriate documentation would
suffice.

Thanks
tim
Jul 23 '05 #1
5 1198
Jc
Tim Johnson wrote:
// etc, etc, works fine BUT, is
// there a component of the DOM that allows me to reference
// the table as a parent?

If so, pointers and URLs to appropriate documentation would
suffice.


The parentNode property should suffice. See the FAQ for links to
applicable documention.

http://jibbering.com/faq

Jul 23 '05 #2
Tim Johnson wrote:
Hi:

Is it possible to reference a table which contains a select list that
has an event handler that modifies the table, without using the table
ID?

Example: <table id="SearchTable">
event handler in select list is
onChange="addTableRow('SearchTable')"
And in addTableRow(), I have the following code:
var tbl = document.getElementById(which);
// etc, etc, works fine BUT, is
// there a component of the DOM that allows me to reference
// the table as a parent?

If so, pointers and URLs to appropriate documentation would
suffice.

Thanks
tim

<table ...>
...
< ... onclick="getTableParent(this)" ...>
...
</table>
<script type="text/javascript">
function getTableParent(x){
while ( "table" != x.nodeName.toLowerCase() && x.parentNode ) {
x = x.parentNode
}
return ( "TABLE" == x.nodeName )? x : null;
}
</script>

However, if you want to add rows, you must to add them to the tbody
element, not the table element. Even if you don't put a tbody
element in the HTML source, the browser will insert one at an
appropriate place. IE will not add a row to a table element, you
must add them to the tbody.

Other browsers will cope with script adding rows to the body (they
work out the tbody was intended), but not IE. If there are multiple
tbody elements, clearly you want to target the right one.

So the function should probably be:

function getTbodyParent(x){
while ( "tbody" != x.nodeName.toLowerCase() && x.parentNode ) {
x = x.parentNode
}
return ( "tbody" == x.nodeName.toLowerCase() )? x : null;
}

And whatever function calls getTbodyParent should ensure that the
return is not null.
--
Rob
Jul 23 '05 #3
Tim Johnson wrote:
Hi:

Is it possible to reference a table which contains a select list that
has an event handler that modifies the table, without using the table
ID?

Example: <table id="SearchTable">
event handler in select list is
onChange="addTableRow('SearchTable')"
And in addTableRow(), I have the following code:
var tbl = document.getElementById(which);
// etc, etc, works fine BUT, is
// there a component of the DOM that allows me to reference
// the table as a parent?


Climb the node tree until the nodeName == "TABLE"
var t;
while(t.parentNode.tagName.toUpperCase()!="TABLE") {
t=t.parentNode;
}

Mick
Jul 23 '05 #4
RobG wrote:
Tim Johnson wrote:

Is it possible to reference a table which contains a select list that
has an event handler that modifies the table, without using the table
ID?

</table>
[...]

<script type="text/javascript">
function getTableParent(x){
while ( "table" != x.nodeName.toLowerCase() && x.parentNode ) {
x = x.parentNode
}
return ( "TABLE" == x.nodeName )? x : null;
}
</script>

[...]
A much better explanation, Rob.
Mick
Jul 23 '05 #5
Tim Johnson wrote:
<...>
If so, pointers and URLs to appropriate documentation would
suffice.

Thanks to everyone for all the good input. I can mine the
heck out of this stuff!
-cheers-
tim
Jul 23 '05 #6

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

Similar topics

2
by: sreddy | last post by:
I am trying to write a sql query on self referencing table. Just to brief ..Database is related to a Hiring department of the Qwest company. I need to generate a Report used by in HR...
2
by: Paul Cook | last post by:
Hi, I have three tables: Countries: ID Country States: ID
6
by: jstaggs39 | last post by:
I want to create a Dcount and an If...Then...Else statement to count the number of records in a table based on the date that is entered to run the form. The If....Else statment comes in because if...
10
by: Macka | last post by:
A few pieces of information first: * I have a class called Folder which represents a row of data in a database table. The data access side of things is not an issue. * The table has a parent...
3
by: Lyners | last post by:
I have a table within a cell of a datagrid. I am doing updates without postback to the server using Javascript. I have everything working, except referencing a table within the datagrid cell. ...
7
by: jmp | last post by:
(I hope this isn't considered too far off-topic.) I work as a developer on a browser product found on handheld devices, and I'm trying to specify behavior for the browser to make it "as...
2
by: libsfan01 | last post by:
Hi all How do u reference the id (and also now i think about it the name) of the enclosing div tag of a form element such as a button or div tag (without specifying its name)? I've tried:...
12
by: rshepard | last post by:
I'm a bit embarrassed to have to ask for help on this, but I'm not finding the solution in the docs I have here. Data are assembled for writing to a database table. A representative tuple looks...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.