473,770 Members | 7,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.getEl ementsByTagName ("BODY")[0];
alert(docBody.t agName);
var t;
var r;
var c;

// Dynamically write out table and header row.
t = document.create Element("table" );
r = t.insertRow();
c = document.create Element("td");
c.appendChild(d ocument.createT extNode("Studen t Name"));
r.appendChild(c );
c = document.create Element("td");
c.appendChild(d ocument.createT extNode("Test#1 "));
r.appendChild(c );
c = document.create Element("td");
c.appendChild(d ocument.createT extNode("Test#2 "));
r.appendChild(c );
c = document.create Element("td");
c.appendChild(d ocument.createT extNode("Test#3 "));
r.appendChild(c );
c = document.create Element("td");
c.appendChild(d ocument.createT extNode("Test#4 "));
r.appendChild(c );
docBody.appendC hild(t);

Dec 19 '05 #1
3 6533


ezmiller wrote:

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


For a start try with
var frameDoc = top.frames[frameName].document;
if (frameDoc) {
var docBody = frameDoc.getEle mentsByTagName( "BODY")[0];
var t = frameDoc.create Element("table" );
// now make sure you use frameDoc.create Element/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.getEl ementsByTagName ("BODY")[0];


For a start try with
var frameDoc = top.frames[frameName].document;
if (frameDoc) {
var docBody = frameDoc.getEle mentsByTagName( "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::g etElementsByTag Name() 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.getEl ementsByTagName ("BODY")[0];
alert(docBody.t agName);


Why use getElementsByTa gName("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
9649
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 assigned to a variable and output using document.write. (Note, there is no submit button or other form elements. Basically
7
18925
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 = "absolute"; t.style.left = "100px"; t.style.top = "100px"; t.style.width = "200px";
4
2224
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 a timeout and call doit() again, and this time, it downloads the picture 30 times!!!! It doesn't even time to finish downloading the pictures before the next timeout kicks off and if I let it go for a minute or two i have like 300 calls to...
11
2085
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 "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
7
3965
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 method access" for the second to last line of my function. If you know what I've done wrong or how to fix it I would appreciate the help.
3
4011
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 with a createElement function to add additional entries. The table has the first row of input text boxes already in it. You have to click a button to add another row. That seems to be working fine. How do I pull the information from the input boxes...
10
1669
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" "http://www.w3.org/TR/html4/loose.dtd">
1
17739
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' src='RasteriserServlet?width=200&amp;height=200&amp;bgColor=#FFFFFF&amp;fgColor=#000000' frameBorder='no' width='200' scrolling='no' height='200' menuId='formControlPopup' childName='frame' showLable='true' labelPosition='bottom'>"); var form = document.createElement("<FORM...
5
13379
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 http://mghospedagem.com/images/controlpanel.jpg instead of http://mghospedagem.comhttp://mghospedagem.com/images/controlpanel.jpg As u see, there's the website URL before the image URL.
0
9592
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
9425
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10230
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
10058
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...
1
10004
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9870
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7416
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
5450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2817
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.