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

JS in tables

I'm putting together some javascript code whose output needs to be
formatted into two columns. I was trying to put it in an html table
until someone alerted me that IE doesn't accept JS within tables. So
I'm looking for workarounds or alternatives. I've Googled and have
found plenty of similar questions, but no concrete solutions.

Someone recommended just putting the table tags (table, tr, td) in
document.write() functions, but this still yields the "Operation
Aborted" error in IE.

Any clues?

-U.

Apr 6 '06 #1
6 1406
U. Cortez - Research said on 07/04/2006 5:24 AM AEST:
I'm putting together some javascript code whose output needs to be
formatted into two columns. I was trying to put it in an html table
until someone alerted me that IE doesn't accept JS within tables. So
IE does 'accept JS in a table'. There are two table-related script
issues with IE:

1. You can't use innerHTML to modify the internal structure

2. If createElement is used to create TR elements, they must
be appended to a tbody element, not the table element.

Other than that, it's business as usual. To modify a table, use DOM
methods. Here's a link to the Mozilla DOM reference for tables:

<URL:http://developer.mozilla.org/en/docs/DOM:table>
If you use insertRow and insertCell to modify your table, you avoid both
the above issues and you should have no problems with modern browsers
(anything after Navigator/IE 4).

Use feature detection to prevent errors in unsupported UAs.
[...]
Someone recommended just putting the table tags (table, tr, td) in
document.write() functions, but this still yields the "Operation
Aborted" error in IE.


You can use document.write to create all or part of a table while the
page loads, but that is not a good idea in general.

e.g.

<table>
<tr><td>top cell</td></tr>
<script type='text/javascript'>
document.write('<tr><td>bottom cell</td></tr>');
</script>
</table>
Using document.write after the page has finished loading will cause the
entire page to be re-written.
--
Rob
Group FAQ: <URL:http://www.jibbering.com/FAQ>
Apr 6 '06 #2
RobG wrote:
<snip>
You can use document.write to create all or part of a
table while the page loads, but that is not a good idea
in general.

e.g.

<table>
<tr><td>top cell</td></tr>
<script type='text/javascript'>
document.write('<tr><td>bottom cell</td></tr>');
</script>
</table>

<snip>

While in reality you can write this code you are opening yourself up to
the vagaries of tag-soup HTML parsing and error correction as it is not
valid HTML. A SCRIPT element may not be a child of a TABLE element, or
the implied TBODY element, so the parser may error-correct the HTML to
imply the closing of the TABLE and TBODY when it encounters the SCRIPT
opening tag and then imply the opening of a new TABLE and TBODY when it
encounters the document written opening TR tag. Then again it may make
the whole lot into a single table. The variable and unpredictable
outcome will likely make the scripted interacting with the resulting
table(s) harder than it needs to be.

Richard.
Apr 7 '06 #3
JRS: In article <11*********************@i39g2000cwa.googlegroups. com>,
dated Thu, 6 Apr 2006 12:24:35 remote, seen in
news:comp.lang.javascript, U. Cortez - Research
<go************@yahoo.com> posted :
I'm putting together some javascript code whose output needs to be
formatted into two columns. I was trying to put it in an html table
until someone alerted me that IE doesn't accept JS within tables. So
I'm looking for workarounds or alternatives. I've Googled and have
found plenty of similar questions, but no concrete solutions.

Someone recommended just putting the table tags (table, tr, td) in
document.write() functions, but this still yields the "Operation
Aborted" error in IE.

Any clues?


Without seeing a minimal demonstration of your actual code, or knowing
which version of IE you are testing with, it's hard to know why it does
not succeed. The following works for me as an HTML page :-

<script>
var Yr=1600, X=4, St
B = "<\/th>\n<\/tr>\n<tr>\n<th>", C = "<\/th>\n<th>"
St = "<table summary=\"T1\" border=1>\n" +
"<caption>TABLE I<\/caption>\n<tr>\n<th>" +
"6543210".split("").join(C) + B +
"BCDEFGA".split("").join(C) + B +
" ".split(" ").join(" <\/th>\n<th>") + " <\/th>\n"
while (Yr<=8500) {
St += "<td>" + Yr ; Yr += 100
if (Yr%400==0) { St += "<br>" + Yr ; Yr += 100 }
St += "<\/td>\n"
X++ ; if (X==7) { X=0 ; St += "<\/tr>\n<tr>\n" } }
St += "<td>&amp;c.<\/td>\n<td>" +
" ".split(" ").join(" <\/td>\n<td>") +
" <\/td>\n<\/tr>\n<\/table>"
document.writeln(St)
</script>

However, it's certainly possible to amend an existing Table after
loading.
Read the newsgroup FAQ.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Apr 7 '06 #4
Ok, to be more specific, I'm trying to insert a Google Map inside one
cell of my table. However, if I do something like:

<table>
<tr><td>
<script type="text/javascript">
//google map code
</script>
</td></tr>
</table>

I get, "Internet Explorer cannot open the Internet site <location>.
Operation aborted"

-U.

Apr 7 '06 #5
> A SCRIPT element may not be a child of a TABLE element, or
the implied TBODY element


Therein lies my problem. I need the output of the script to be
displayed within the table. How can I work around this limitation in
IE?

-U.

Apr 7 '06 #6
U. Cortez - Research wrote on 07 apr 2006 in comp.lang.javascript:
A SCRIPT element may not be a child of a TABLE element, or
the implied TBODY element


Therein lies my problem. I need the output of the script to be
displayed within the table. How can I work around this limitation in
IE?


Use the DOM.

Or wrie your whole HTML as a string to be document.written.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Apr 7 '06 #7

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

Similar topics

44
by: Mariusz Jedrzejewski | last post by:
Hi, I'll be very grateful if somebody can explain me why my Opera 7.23 (runing under linux) doesn't show me inner tables. Using below code I can see only "inner table 1". There is no problem with...
3
by: Random Person | last post by:
Does anyone know how to use VBA to relink tables between two MS Access databases? We have two databases, one with VBA code and the other with data tables. The tables are referenced by linked...
11
by: dskillingstad | last post by:
I've been struggling with this problem for some time and have tried multiple solutions with no luck. Let me start with, I'm a novice at Access and I'm not looking for someones help to design my...
2
by: Jill Elaine | last post by:
I am building an Access 2002 frontend with linked tables to an encrypted Paradox 7 database. When I first create these linked tables, I'm asked for the password to the encrypted Paradox database,...
1
by: Shelby | last post by:
Problem: My company generates its own data export from a propietary database. These (free) tables can be read in C#.NET using a Visual FoxPro driver (vfpoledb). I can read each of the six tables...
59
by: phil-news-nospam | last post by:
In followups by Brian O'Connor (ironcorona) to other posts, he repeats the idea that using tables in CSS is not something that should be done because IE doesn't support it. Of course I'm not happy...
5
by: rdemyan via AccessMonster.com | last post by:
I have a need to add another field to all of my tables (over 150). Not data, but an actual field. Can I code this somehow. So the code presumabley would loop through all the tables, open each...
4
by: db2admin | last post by:
Hello, I want to plan rearranging tables in our database according to business areas. say all tables in business area A will be in seperate tablespace or tablespaces. I am planning to monitor...
25
by: bubbles | last post by:
Using Access 2003 front-end, with SQL Server 2005 backend. I need to make the front-end application automatically refresh the linked SQL Server tables. New tables will be added dynamically in...
11
by: shriil | last post by:
Hi I have this database that calculates and stores the incentive amount earned by employees of a particular department. Each record is entered by entering the Date, Shift (morn, eve, or night)...
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...
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.