473,732 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem dynamically adding data to an existing table ...

I've done this before while creating a brand new table.
But the code below is not working and I keep getting the error:
"Internet Explorer cannot open the Internet site .....
Operation aborted"

Here is the code:

myBody=document .getElementsByT agName("body"). item(0);
mytablebody = document.getEle mentById('produ ct').getElement sByTagName("TBO DY" )[0];

newrow=document .createElement( "TR");
newrow.setAttri bute("bgColor", "#EFECCB");

//Family
newcell=documen t.createElement ("TD");
currenttext=doc ument.createTex tNode("Family") ;
newcell.appendC hild(currenttex t);
newcell.setAttr ibute("width"," 10");
newcell.setAttr ibute("align", "center");
newrow.appendCh ild(newcell);
//Product Description
newcell=documen t.createElement ("TD");
currenttext=doc ument.createTex tNode("Product Description");
newcell.appendC hild(currenttex t);
newcell.setAttr ibute("align", "center");
newrow.appendCh ild(newcell);
mytablebody.app endChild(newrow );

It's pretty basic code. I put the TR, TD, TD in by hand and it worked fine.
I wanted to make sure it wasn't because I had some mismatching <TABLE> tags.

Any ideas?
Melissa Mussitsch
Jul 23 '05 #1
10 1746


Melissa Mussitsch wrote:
I've done this before while creating a brand new table.
But the code below is not working and I keep getting the error:
"Internet Explorer cannot open the Internet site .....
Operation aborted"

Here is the code:

myBody=document .getElementsByT agName("body"). item(0);
mytablebody = document.getEle mentById('produ ct').getElement sByTagName("TBO DY" )[0];

newrow=document .createElement( "TR");
newrow.setAttri bute("bgColor", "#EFECCB");

//Family
newcell=documen t.createElement ("TD");
currenttext=doc ument.createTex tNode("Family") ;
newcell.appendC hild(currenttex t);
newcell.setAttr ibute("width"," 10");
newcell.setAttr ibute("align", "center");
newrow.appendCh ild(newcell);
//Product Description
newcell=documen t.createElement ("TD");
currenttext=doc ument.createTex tNode("Product Description");
newcell.appendC hild(currenttex t);
newcell.setAttr ibute("align", "center");
newrow.appendCh ild(newcell);
mytablebody.app endChild(newrow );

It's pretty basic code. I put the TR, TD, TD in by hand and it worked fine.
I wanted to make sure it wasn't because I had some mismatching <TABLE> tags.

Any ideas?


Are you sure that your code posted above causes the "error"? How do you
call that code? It seems more likely that you have some link causing
that message.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
Well after doing further research, I see that the error message is a
pretty standard one and could mean a number of things. I ended up
getting the code to write one row successfully. However, at the very
end, I still get this error. And the only thing left after these
statements is </FORM></BODY></HTML>!
For this project I've tried adding this code to an already enormous asp
page. I think I'm going to have to split it out to get it working and
then try to plug it back in. I don't get it when I pull that code back
out though.

I have this code called after variables and arrays are filled in and
some web form objects are already drawn on the page. I simply have my
<SCRIPT> tag and call the function to create the table and write a
couple rows (for now). When I remove these three lines from my code I
don't get the error:
1)<SCRIPT language=""Java Script"">var
mybody=document .getElementsByT agName("body"). item(0);mytable =document.cr
eateElement("TA BLE");</SCRIPT>
2)<SCRIPT language=""Java Script"">WriteT able(mytable,<% =iarrMax%>, '',
'');</SCRIPT>
3)<SCRIPT language=""Java Script"">mybody .appendChild(my table);</SCRIPT>

Of course WriteTable does most of the work.

Thank you.
Melissa M

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #3
Ok - I've been able to simplify this and still get the error.

Again I have three lines:
<SCRIPT language="JavaS cript">var
mybody=document .getElementsByT agName("body"). item(0);mytable =document.cr
eateElement("TA BLE");</SCRIPT>
<SCRIPT language="JavaS cript">WritePro ductList(mytabl e,
<%=iarrMax%>) ;</SCRIPT>
<SCRIPT language="JavaS cript">mybody.a ppendChild(myta ble);</SCRIPT>

Here is the code for WriteProductLis t:
function WriteProductLis t(mytable, iarrMax) {

var mytablebody;
var newrow;
var newcell;
var currenttext;

mytable.setAttr ibute("width"," 100%");
mytable.setAttr ibute("border", "1");
mytable.setAttr ibute("id","pro ductselect");
mytablebody=doc ument.createEle ment("TBODY");

newrow=document .createElement( "TR");

//Family
newcell=documen t.createElement ("TD");
currenttext=doc ument.createTex tNode("Family") ;
newcell.appendC hild(currenttex t);
newrow.appendCh ild(newcell);
newrow.appendCh ild(newcell);

mytablebody.app endChild(newrow );
mytable.appendC hild(mytablebod y);
}

It's very simple in that it writes one row to the table.
Let me say that I am getting my row in the table.
But as soon as it gets to the "mybody.appendC hild(mytable);" part, the
error appears. And without it, I don't get the row.

Does anyone see something obviously wrong?

Thank you.
Melissa M

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #4
Ok - sorry for all the threads. I know it has to be something stupid
because I've ripped it all out and have a very simple ASP page and still
get the error. I've even copied an example from online. I've spent
hours on this - please let me know if you see something wrong!

<%Response.Buff er = True
%>

<html>
<head>
<title>Eval Center</title>

<SCRIPT language="JavaS cript">
function WriteProductLis t() {

var mybody=document .getElementsByT agName("body"). item(0);
mytable = document.create Element("TABLE" );
mytablebody = document.create Element("TBODY" );
for(j=0;j<2;j++ ) {
mycurrent_row=d ocument.createE lement("TR");
for(i=0;i<2;i++ ) {
mycurrent_cell= document.create Element("TD");
currenttext=doc ument.createTex tNode("cell is row "+j+", column
"+i);
mycurrent_cell. appendChild(cur renttext);
mycurrent_row.a ppendChild(mycu rrent_cell);
}
mytablebody.app endChild(mycurr ent_row);
}
mytable.appendC hild(mytablebod y);
mybody.appendCh ild(mytable);
mytable.setAttr ibute("border", "2");
}
</SCRIPT>

</head>

<body>
<form>

<SCRIPT language="JavaS cript">WritePro ductList();</SCRIPT>
</form>

</body>
</html>

Thank you.
Melissa M

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #5
Melissa Mussitsch wrote:
Ok - sorry for all the threads. I know it has to be something stupid
because I've ripped it all out and have a very simple ASP page and still
Ahh, yes, incredibly stupid :-) in fact ... you'll kikc yourself.
I was going to write this at the very bottom, but I'll let you know
now:

Because you didn't specify an action on your form element, IE barfs.
Why is open to conjecture - either get rid of the form or add an
action:

<form action="">
...

A good reason to post code, 'cos your problem wasn't JS or ASP but HTML
and IE combined (Firefox was quite happy with the errant tag).

Even though your JS works fine, a couple of hints (please ignore if you
have already dealt with them):
var mybody=document .getElementsByT agName("body"). item(0);
You should do feature detection before using getElements... and use an
alternative if it fails. There are plenty of examples in the archives.
mytable = document.create Element("TABLE" );
mytablebody = document.create Element("TBODY" );
for(j=0;j<2;j++ ) {
mycurrent_row=d ocument.createE lement("TR");
Use "var" to keep mycurrent_row local. It's probably trivial here,
but worth doing.

var mycurrent_row=d ocument.createE lement("TR");
for(i=0;i<2;i++ ) {
mycurrent_cell= document.create Element("TD");
same for mycurrent_cell and currenttext...
currenttext=doc ument.createTex tNode("cell is row "+j+", column
"+i);
mycurrent_cell. appendChild(cur renttext);
mycurrent_row.a ppendChild(mycu rrent_cell);
}
mytablebody.app endChild(mycurr ent_row);
}
mytable.appendC hild(mytablebod y);
mybody.appendCh ild(mytable);
mytable.setAttr ibute("border", "2");
Using "setAttribu te" destroys any attributes that the element already
has, so it's not considered nice. Again, probably trivial but may
cause you problems later if you use it twice on the same element. Try:

mytable.style.b order = 'thin solid red';

For a border, you have to set all the attributes, either in one go as
above or individually:

mytable.style.b orderWidth = 'thin';
mytable.style.b orderStyle = 'solid';
mytable.style.b orderColor = 'red';

It's probably better to do the style attributes before adding the row
to the table too:

mytable.style.b order = 'thin solid red';
mybody.appendCh ild(mytable);
}
</SCRIPT>

</head>

<body>
<form>
The form element should have an action, even if it's action=""

<SCRIPT language="JavaS cript">WritePro ductList();</SCRIPT>
</form>


I guess you've put the table inside a form to help layout the form
elements - otherwise, there is no need for it.

Anyhow, all just advice, none of it will fix your problem. :-)

Cheers, Rob.

Jul 23 '05 #6
RobG wrote:
[...]
Ahh, yes, incredibly stupid :-) in fact ... you'll kikc yourself.
I was going to write this at the very bottom, but I'll let you know
now:

Because you didn't specify an action on your form element, IE barfs.
Why is open to conjecture - either get rid of the form or add an
action:

<form action="">
...


Ahhh, ooops!! I also moved calling the function to:

<body onload="WritePr oductList();">

and got rid of the <script...> in the form - that was the *real* fix!

Sorry about that. :-p

Rob
Jul 23 '05 #7
Well I answered my own question.
Once I appended the table to my form it worked.

Thank you for directing me to the form, I would have never looked there.
And I will look again at your suggestions.

Thank you for all your time and help!
Melissa M

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #8
Oh - Just for kicks I did test <SCRIPT
language="JavaS cript">alert('h i');</SCRIPT> inside the form and it works
fine. So I guess it's not the <SCRIPT> tag itself but the dynamic
building of the tables.

I wish I knew specifically what it didn't like.
It seems to be appending the table to the body when I got the error. Do
you think I need to append the table to the form object instead?

Thank you.
Melissa M

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #9
Ok. I'm still confused.
I'm working now just with my simple example.
I took the <form> totally out and as you mentioned, it gets rid of the
error.

However, I think that I do need the form. I may be able to get away
without it. Ultimately I'll need to be able to retrieve all values from
a different table. And if I traverse using DOM, perhaps I won't need
the form. But just in case, I tried (in my simple example) to add <form
action="" name="mainform" method="post"> and I get the error again.

So - I believe you're right in the <form> does not like the <script>
call to my table build inside it. I just confirmed in my other
application that I swore was working with all this - I ended the </form>
prior to call the <script> which is why it works. (I just got lucky
there)

I appreciate all your other suggestions above. I've taken most of this
dynamic table creation from the internet and love the flexibility and
power of it, but probably don't do it all the best way. I shift things
all around until it works and especially didn't realize there was a
better order to the attributes.

If you can think of anyway the <FORM> will allow the <SCRIPT>, please
let me know. Otherwise, I'll try to work without the form.

Thanks so much for your help! This just about killed me yesterday!

Thank you.
Melissa M

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #10

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

Similar topics

3
9070
by: RAD | last post by:
I am working with an evaluation copy of SQL Server 2000 for the first time; my DB experience lies with MS Access. I have a simple table in SQL Server (tblCompany) that has a field called "Ticker." When new company stock tickers (i.e., MSFT for Microsoft) are entered into the field, I'd like them in all caps--whether the user types msft, Msft, MsFt, etc. In Access, this was easy--simply set the Format to ">" in table design view. In...
10
7793
by: Richard A. DeVenezia | last post by:
At line this.timerId = setInterval (function(){this.step()}, 100) I get error dialog Error:Object doesn't support this property or method. If I change it to this.timerId = setInterval (function(){this==window}, 100) I see true, the sad fact that 'this' is window and not an anim. What are some proper ways ? I would like to avoid
8
2942
by: Kevin Little | last post by:
#!/usr/bin/env python ''' I want to dynamically add or replace bound methods in a class. I want the modifications to be immediately effective across all instances, whether created before or after the class was modified. I need this to work for both old ('classic') and new style classes, at both 2.3 and 2.4. I of course want to avoid side effects, and to make the solution as light-weight as possible.
4
1664
by: Catherine Jo Morgan | last post by:
This is still for the db for the recreational tree climbing business. I thought I'd solved the problem of clients often being part of the same household, with a tblHouseholds, with Household as a FK in the Persons table. The main reason for a Households table is to give an appropriate mailing name for the household address, e.g. "The Brown Family" or "Jim & Jean Smith." This looks good to me till I consider when and how the household...
3
4906
by: Raj | last post by:
Hi, I am trying to add some more information to the table which already has a lot a data (like 2-3000 records). The new information may be adding 2-3 new columns worth. Now my questions are: (1)Is it a good idea to add new columns to the existing table? then it will create these new columns for all old records, will it not result in wasting a lot of space?? (2)Is it a good idea to create a new table with the new information and have as a...
0
2473
by: sameer mowade via .NET 247 | last post by:
Hello All, I have problem while dynamically removing row from the Datagrid which i have added dynamically as shown in the following code snippet. The problem is that while removing dynamically added row it also removes the row at the end along with the added row. Plz tell me if, I am missing any thing. Code </asp:datagrid>
6
7015
by: Robin Bonin | last post by:
In my user contol I am creating a set of dropdownlists. Each list is created based on input from the other lists. The problem I am having is setting the selected index on the lists. If someone changes box1, I want to set the selected index in box2 = 0. When I do this, I dont get an error, but when the page loads, it still has the selected value and not 0. It seems that it is getting the selected value from the viewstate
3
2343
by: Ankit Aneja | last post by:
I have a strange situation and I have no idea how to solve this. Its a Recruitment Search Page,in the Admin Page, for every button click event the Admin Person has to create a checkbox on the users page. So whenever the Admin person comes to know about the new category in the market he will be adding as different Sub-Categories for example ABAP, BDC etc..etc.. on every click event as Checkboxes. And these controls(checkboxes) should remain...
4
2223
by: nanabuch | last post by:
Hello, I am new to this forum, and I am a newbit in Oracle, I do have a background in MS Access, VBA, SQL server development and some Oracle backend development work. I have been giving a task to dynamically create tables through code based on parameters in existing tables. I will try to keep this short and to the point The goal is to extract values from existing tables I will give an example of two tables to keep it simple
0
8946
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
8774
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
9447
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
9307
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
9181
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...
0
8186
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
6735
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
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.