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

Trouble using appendChild for document body in another frame

So I have some code that gets the body element of another frame and
then tries to
dynamically write a table. The code fails when, after creating the
table, I try to
append it to the document. I get an invalid argument error.

Here's the code....

var docBody =
top.frames[frameName].document.getElementsByTagName("BODY")[0];
alert(docBody.tagName);
var t;
var r;
var c;

// Dynamically write out table and header row.
t = document.createElement("table");
r = t.insertRow();
c = document.createElement("td");
c.appendChild(document.createTextNode("Student Name"));
r.appendChild(c);
c = document.createElement("td");
c.appendChild(document.createTextNode("Test#1"));
r.appendChild(c);
c = document.createElement("td");
c.appendChild(document.createTextNode("Test#2"));
r.appendChild(c);
c = document.createElement("td");
c.appendChild(document.createTextNode("Test#3"));
r.appendChild(c);
c = document.createElement("td");
c.appendChild(document.createTextNode("Test#4"));
r.appendChild(c);
docBody.appendChild(t);

Dec 19 '05 #1
3 6516


ezmiller wrote:

var docBody =
top.frames[frameName].document.getElementsByTagName("BODY")[0];


For a start try with
var frameDoc = top.frames[frameName].document;
if (frameDoc) {
var docBody = frameDoc.getElementsByTagName("BODY")[0];
var t = frameDoc.createElement("table");
// now make sure you use frameDoc.createElement/createTextNode
// to create any elements or text nodes
// supposed to be inserted in that frame
--

Martin Honnen
http://JavaScript.FAQTs.com/
Dec 19 '05 #2
Martin Honnen wrote:
ezmiller wrote:
var docBody =
top.frames[frameName].document.getElementsByTagName("BODY")[0];


For a start try with
var frameDoc = top.frames[frameName].document;
if (frameDoc) {
var docBody = frameDoc.getElementsByTagName("BODY")[0];


HTMLDocument objects have a `body' property that refers to
a HTMLBodyElement object which in turn represents the
`body' element of the document. There is no need to use
HTMLDocument::getElementsByTagName() here.

<URL:http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-26809268>
PointedEars
Dec 19 '05 #3
ezmiller wrote:
So I have some code that gets the body element of another frame and
then tries to
dynamically write a table. The code fails when, after creating the
table, I try to
append it to the document. I get an invalid argument error.

Have you tried a minimal test case? Start with ONLY one element, then
build up from there until it doesn't work.

I can't see offhand what's wrong with what you're doing, but I'll bet
that will help narrow it down.

var docBody =
top.frames[frameName].document.getElementsByTagName("BODY")[0];
alert(docBody.tagName);


Why use getElementsByTagName("BODY") - rather than just document.body ?
Maybe this is the problem?

Dec 19 '05 #4

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

Similar topics

13
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be...
7
by: Andrew Poulos | last post by:
I'm using the following code to create a small table with one column and two rows. An image goes into the first cell. //create table var t = document.createElement("TABLE"); t.style.position =...
4
by: matty | last post by:
Hello, here is an example of what is driving me totally crazy. This example will show that the first call to "doit()" will print 30 times the image with only one call to the server. Then I have...
11
by: Mellow Crow | last post by:
I had a problem in IE 6 when trying to insert a table using W3C DOM techniques. I found a solution and share it. :) Initially I had...... ********************** <!DOCTYPE html PUBLIC...
7
by: petermichaux | last post by:
Hi, I have tried the following based on suggestions of the best way to insert JavaScript into a page. This is instead of using eval(). Unfortunately IE says "unexpected call to property or...
3
by: acecraig100 | last post by:
I am fairly new to Javascript. I have a form that users fill out to enter an animal to exhibit at a fair. Because we have no way of knowing, how many animals a user may enter, I created a table...
10
by: whisher | last post by:
Hi. I'm not able to understand why this simple snippet doesn't work with IE. It works fine with FF and Opera 9. Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"...
1
by: Dmitry Kulinich | last post by:
var iframe = document.createElement("<IFRAME id='frame0' style='PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px' border='no' name='frame0'...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.