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

inserting a col tag in a table using DOM problem!!

MQ
I have been trying to insert a col tag using DOM but I can't seem to make it
work. In the following script I create a table with rows and columsn. I
tried to modify the column style, but doesn't seem to want to work. I tried
modifying the cell style and it works fine. Can anyone see what's wrong
with this code.

Thank you.
-------code-----------
<html>

<head>
<title>
</title>

<script language="Javascript">
function Table(rows, columns, id)
{
var cellAttrib;
var colAttrib;
var myLocation = document.getElementById(id);
mytable = document.createElement("TABLE");
mytablebody = document.createElement("TBODY");
for (i = 0; i < columns; i++)
{
myColumn = document.createElement("COL");
myColumn.setAttribute("id","col_" + i);
mytablebody.appendChild(myColumn);
}
for(j = 0; j < rows; j++)
{
mycurrent_row = document.createElement("TR");
for(i = 0; i < columns; i++)
{
mycurrent_cell = document.createElement("TD");
currenttext = document.createTextNode("cell is row " + j + ",
column " + i);
mycurrent_cell.appendChild(currenttext);
mycurrent_cell.setAttribute("id","cell_" + j + "_" + i);
mycurrent_row.appendChild(mycurrent_cell);
}
mytablebody.appendChild(mycurrent_row);
}
mytable.appendChild(mytablebody);
myLocation.appendChild(mytable);
mytable.setAttribute("border","2");
}
</script>

</head>

<body >
<div id="actionGridID">
</div>
<script language="Javascript">
<!--
var myTable = new Table(10, 5, "actionGridID");

document.all['col_1'].style.color = 'red';
-->
</script>

</body>

</html>
--

Jul 23 '05 #1
1 3320


MQ wrote:
I have been trying to insert a col tag using DOM but I can't seem to make it
work. In the following script I create a table with rows and columsn. I
tried to modify the column style, but doesn't seem to want to work. I tried
modifying the cell style and it works fine.


With the following corrections made the script does set the
background-color of the column with Opera 7.50 and Mozilla 1.7, it
doesn't achieve that with IE 6 however:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>setting CSS style of col element</title>

<script type="text/javascript">
function Table(rows, columns, id)
{
var cellAttrib;
var colAttrib;
var myLocation = document.getElementById(id);
mytable = document.createElement("TABLE");
mytablebody = document.createElement("TBODY");
for (var i = 0; i < columns; i++)
{
myColumn = document.createElement("COL");
myColumn.setAttribute("id","col_" + i);
mytable.appendChild(myColumn);
}
for(var j = 0; j < rows; j++)
{
mycurrent_row = document.createElement("TR");
for(var i = 0; i < columns; i++)
{
mycurrent_cell = document.createElement("TD");
currenttext = document.createTextNode("cell is row " + j +
", column " + i);
mycurrent_cell.appendChild(currenttext);
mycurrent_cell.setAttribute("id","cell_" + j + "_" + i);
mycurrent_row.appendChild(mycurrent_cell);
}
mytablebody.appendChild(mycurrent_row);
}
mytable.appendChild(mytablebody);
myLocation.appendChild(mytable);
mytable.setAttribute("border","2");
}
</script>

</head>

<body >
<div id="actionGridID">
</div>
<script type="text/javascript">

var myTable = new Table(10, 5, "actionGridID");

document.getElementById('col_1').style.backgroundC olor = 'red';
</script>

</body>

</html>

According to the CSS 2 specification at
http://www.w3.org/TR/CSS2/tables.html#q4
color is not one of the CSS properties that can be applied to columns
thus I have changed the example to use background-color. And the <col>
elements need to be a child of the table element not the tbody.
Mozilla I think needs to be in strict layout mode to apply column styles
thus I added the DOCTYPE declaration.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #2

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

Similar topics

0
by: Marko Poutiainen | last post by:
Situation: We had to make our SQLServer 2000 database multi-lingual. That is, certain things (such as product names) in the database should be shown in the language the user is using (Finnish,...
3
by: ben.saur | last post by:
I am having a problem viewing a centered table using Firefox. When the page is long enough to scroll, the alignment moves slightly to the left. The alignment doesn't change when I view the page...
2
by: Max | last post by:
Hi, I have the following problem. I want to insert records into one table using the combination of two other tables. Here is a simplified example: Let's say the first table has a column with...
0
by: Thomas Scheiderich | last post by:
I have a table that has 3 image slices. The middle slice changes size based on size of browser window. This works great. My client wants the date to show over the image on the right. So what I...
2
by: Laphan | last post by:
AAAAARRRRGGGGHHHH!!! Everything appears to be great in doing a web-based editor using the execCommands apart from the fact that there is no method to insert a table. I've seen somebody suggest...
3
by: ramakanth05 | last post by:
Hi, I have a problem pulling data from a table using the parameter as table name. I have three tables tbl1, tbl2, tbl3 and I want all the records of the table based on the parameter given. ...
0
by: yuenli | last post by:
Hi! I am using Microsoft Office Interop Power Point to build a Power Point Automation program. Does anyone know how to insert a table in the power point slide using the above object library?...
13
nabh4u
by: nabh4u | last post by:
hi, I am trying to insert multiple rows in a table using PL/SQL. I have two procedures and two tables. the first procedure gets the data from the source table, manipulates it and then sends the...
6
by: =?Utf-8?B?RGFu?= | last post by:
I am reposting a question from about 3 weeks ago ("sorting capability"). I have an aspx page in which I get the data from a database dynamically, through C# code, by creating a dynamic table...
5
by: thatcollegeguy | last post by:
Below are my 3php and 2js files. I create a table using ajax/php and then want to change the values in the tables add(+ number for teamid) id's for each specific td in the table. I don't know...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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
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.