473,324 Members | 2,257 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,324 software developers and data experts.

add row to table from child window

I am adding a row to a table from a child window that opened from the
parent window.

My js looks like:

if ( self.opener.document.update )
{
var rows = self.opener.document.getElementById("A_Table");
myTR = self.opener.document.createElement("TR");
myTD=self.opener.document.createElement("TD");
myTEXT =
self.opener.document.createTextNode("test"); myTD.appendChild(myTEXT); myTR.appendChild(myTD); rows.appendChild(myTR);
}

This looks like it is executing, but i don't get anything showing up in
my parent window in the table. The table exists with an id="A_Table".

I'm concerned about the statement "rows.appendChild(myTR);"

Is this correct?

Mike

Oct 6 '05 #1
5 6179
mike wrote:
I am adding a row to a table from a child window that opened from the
parent window.

My js looks like:

if ( self.opener.document.update )
{
var rows = self.opener.document.getElementById("A_Table");
From the ID, it seems 'rows' is a reference to a table. That is
unfortunate since the table has a rows collection. I'd call that
variable 'aTable' or similar, 'cos now your reference to the rows
collection will be:

var rowsCollection = rows.rows;
myTR = self.opener.document.createElement("TR");
myTD=self.opener.document.createElement("TD");
myTEXT =
self.opener.document.createTextNode("test"); myTD.appendChild(myTEXT); myTR.appendChild(myTD); rows.appendChild(myTR);
}
Do myTR, myTD, myTEXT need to be global? Better to keep them local.

This looks like it is executing, but i don't get anything showing up in
my parent window in the table. The table exists with an id="A_Table".
I'll guess that you are using IE, 'cos it refuses to add rows to the
table element, you have to add them to the tbody. A tbody is mandatory
but you don't have to include the tags in the source HTML, your browser
will insert it anyway.

So either:

- code a tbody element in your HTML and use that exactly as you are
currently using the table

- use insert row instead of appendChild

- get the last row and add the new row as the next sibling, e.g.

var lastRow = rows[rows.length-1];
lastRow.parentNode.appendChild(myTR);
Since the lastRow's parent will be the tbody, you don't need to worry
about whether it has been coded in the HTML or change your use of the
table ID.

I'm concerned about the statement "rows.appendChild(myTR);"

Is this correct?


Yes, you are correct to be concerned about it. :-)

--
Rob
Oct 6 '05 #2
RobG wrote:
[...]
So either:

- code a tbody element in your HTML and use that exactly as you are
currently using the table

- use insert row instead of appendChild

- get the last row and add the new row as the next sibling, e.g.

var lastRow = rows[rows.length-1];
lastRow.parentNode.appendChild(myTR);


Aggh, fell into my own trap!!

var lastRow = rows.rows[rows.rows.length-1];
lastRow.parentNode.appendChild(myTR);

See, using aTable (or I guess myTable) instead of 'rows' would be clearer:

var lastRow = myTable.rows[myTable.rows.length-1];
lastRow.parentNode.appendChild(myTR);
[...]
--
Rob
Oct 6 '05 #3
mike wrote:
I am adding a row to a table from a child window that
opened from the parent window.

My js looks like:

if ( self.opener.document.update )
{
var rows = self.opener.document.getElementById("A_Table");
Is this "A_Table" a TABLE or a TBODY, THEAD or TFOOT element?
myTR = self.opener.document.createElement("TR"); <snip> rows.appendChild(myTR); }

<snip>

A TR element is not allowed as a child of a TABLE element in HTML (see
the HTML DTDs for details).

Richard.
Oct 6 '05 #4
That is absolutly correct. I don't have a tbody element and I am using
IE. Let me make a change and see if that helps.

Oct 7 '05 #5
Well, That worked. I appreciate it.

It was confusing, because I have some other code like this where it is
in the same document and rows.appendChild(myTR); worked albeit with a
tbody defined in the document.

Thanks, Mike

Oct 7 '05 #6

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

Similar topics

6
by: Amir Hardon | last post by:
I'm new to DOM and can't figure out this thing: I'm trying to add a row to a table with a form field in one of it's cells, but if I'm appending the field to a form it gets out of the table. Can...
1
by: ajay | last post by:
I have following code for a slide menu but i twiked it to work for a single level menu. Open it in a Browser to get a clear picture. I have 2 Qs 1) How to make first entry as non-link. i.e i...
1
by: Sean | last post by:
I have a table (with tabular data) that I want to display on a webpage. Initially the talbe is empty. When a user clicks on a button, a child window opens up with a form and some text fields. ...
2
by: Bostonasian | last post by:
I am trying to append options to dropdown in parent window from option items in child window. In parent window, I have following code: <script language="javascript"> function...
1
by: Earl Teigrob | last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at...
7
by: Kamal | last post by:
Hello all, I have a very simple html table with collapsible rows and sorting capabilities. The collapsible row is hidden with css rule (display:none). When one clicks in the left of the...
2
by: markszlazak | last post by:
I'm a relatively slow response of table cells changing their background color with mouseover/our in IE6 (Win 2K) but the response is fine (fast) in Firefox. Why? The code is below. Sorry about the...
4
by: Buddha | last post by:
Hello, I posted this on two forums, without too much help .. and I am kinda stuck in this. I need to refresh the parent page from the second child window which is opened by the first child and...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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...
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....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.