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

Problem setting attriibutes in JS

I'm trying to mess about with a table using javascript. I'm deleting the
current row then adding a new row and adding a couple of columns. I then
want to add either a style attribute and add a border to the bottom of one
of the cells or add a class attribute and set it up in the stylesheet.
Problem is, when I try to use the setAttribute it doesn't do anything. In
fact when I try and set any attribute of cellLeft or cellRight such as
bgcolor=red; it does nothing. It sets the width ok though!

Can anyone spot the problem?? Codes below..

Cheers,
Andy
<SCRIPT LANGUAGE='JavaScript1.2'>
function setMenuComment(arg)
{
//remove row
var tbl = document.getElementById('menuCommentTable');
var lastRow = tbl.rows.length;
if (lastRow > 0) tbl.deleteRow(lastRow - 1);

//add row
var lastRow = tbl.rows.length;
var iteration = lastRow + 1;
var row = tbl.insertRow(lastRow);
row.setAttribute('align', 'left');

// left cell
var cellLeft = row.insertCell(0);
blank = document.createTextNode('blank');
cellLeft.appendChild(blank);

// right cell
var cellRight = row.insertCell(1);

var pEl = document.createElement('p');
if(arg=='main'){ text = document.createTextNode('introduction area');
cellRight.setAttribute('width','750');}
else if(arg=='cv'){ text = document.createTextNode('personal profile and
information'); cellRight.setAttribute('width','600');}
else if(arg=='downloads'){ text = document.createTextNode('software and
documents to download'); cellRight.setAttribute('width','450');}
else if(arg=='links'){ text = document.createTextNode('links to other
sites of interest'); cellRight.setAttribute('width','300');}
pEl.appendChild(text);
cellRight.appendChild(pEl);
cellRight.setAttribute("class", "menuInfo") ;
}
</SCRIPT>

//html
<!-- Menu Info Area -->
<tr><td border="0">
<table border="0" align="center" cellpadding="0"
cellspacing="0" vspace="0" id="menuCommentTable">
<tr>
<td class="menuBar" width="100%"
style="border-bottom:1px solid #DCDCDC"><a>&nbsp;</a></td>
</tr>
</table>
</td></tr>
//stylesheet
td.menuInfo
{
border-left:1px solid #DCDCDC;
border-bottom:1px solid #EFEFEF;
height: 20;
text-align: left;
vertical-align: middle;
line-height: 1;
}
Jul 23 '05 #1
3 1446


AndyG wrote:

cellRight.setAttribute("class", "menuInfo") ;


Use
cellRight.className = "menuInfo";
setAttribute in IE is misbehaving so you are better off scripting
properties and that way the script is working in other browsers too.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
On Thu, 30 Sep 2004 13:47:35 +0100, AndyG <An************@BAAESYSTMES.COM>
wrote:
I'm trying to mess about with a table using javascript. I'm deleting the
current row then adding a new row and adding a couple of columns. I then
want to add either a style attribute and add a border to the bottom of
one
of the cells or add a class attribute and set it up in the stylesheet.
Problem is, when I try to use the setAttribute it doesn't do anything.
Don't use setAttribute in HTML documents. As far as I know, all standard
attributes have shortcut properties available. So, setting the class
changes from:

element.setAttribute('class', '...');

to

element.className = '...';
From:

element.setAttribute('width', '8em');

to

element.width = '8em';
That may, or may not, solve your problem.
In fact when I try and set any attribute of cellLeft or cellRight such as
bgcolor=red; it does nothing. It sets the width ok though!
All of those attributes are deprecated. I don't think cellLeft/Right even
exist. If they do, they're proprietary.

Use CSS. No align attributes. No bgcolor. Just up-to-date, structural
mark-up.

[snip]
<SCRIPT LANGUAGE='JavaScript1.2'>
Dear Lord! Don't EVER use JavaScript1.2 as the language specification
unless you know what you're doing. The language rules changed in that
version and Netscape-like browsers respect those changes.

Stick to the type attribute. It's required anyway, and makes the language
attribute redundant.

<script type="text/javascript">
function setMenuComment(arg)
{
//remove row
var tbl = document.getElementById('menuCommentTable');
var lastRow = tbl.rows.length;
if (lastRow > 0) tbl.deleteRow(lastRow - 1);


[snip]

If this code is for the Web, read up on feature detection. Not all
browsers in use support DOM methods and properties.

<URL:http://jibbering.com/faq/#FAQ4_26>

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #3
Thanks, that worked

"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:opse45apr2x13kvk@atlantis...
On Thu, 30 Sep 2004 13:47:35 +0100, AndyG <An************@BAAESYSTMES.COM>
wrote:
I'm trying to mess about with a table using javascript. I'm deleting the
current row then adding a new row and adding a couple of columns. I then
want to add either a style attribute and add a border to the bottom of
one
of the cells or add a class attribute and set it up in the stylesheet.
Problem is, when I try to use the setAttribute it doesn't do anything.


Don't use setAttribute in HTML documents. As far as I know, all standard
attributes have shortcut properties available. So, setting the class
changes from:

element.setAttribute('class', '...');

to

element.className = '...';
From:

element.setAttribute('width', '8em');

to

element.width = '8em';
That may, or may not, solve your problem.
In fact when I try and set any attribute of cellLeft or cellRight such as bgcolor=red; it does nothing. It sets the width ok though!


All of those attributes are deprecated. I don't think cellLeft/Right even
exist. If they do, they're proprietary.

Use CSS. No align attributes. No bgcolor. Just up-to-date, structural
mark-up.

[snip]
<SCRIPT LANGUAGE='JavaScript1.2'>


Dear Lord! Don't EVER use JavaScript1.2 as the language specification
unless you know what you're doing. The language rules changed in that
version and Netscape-like browsers respect those changes.

Stick to the type attribute. It's required anyway, and makes the language
attribute redundant.

<script type="text/javascript">
function setMenuComment(arg)
{
//remove row
var tbl = document.getElementById('menuCommentTable');
var lastRow = tbl.rows.length;
if (lastRow > 0) tbl.deleteRow(lastRow - 1);


[snip]

If this code is for the Web, read up on feature detection. Not all
browsers in use support DOM methods and properties.

<URL:http://jibbering.com/faq/#FAQ4_26>

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.

Jul 23 '05 #4

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

Similar topics

1
by: void | last post by:
Please take a look at this page: http://home.comcast.net/~delerious1/index5.html It behaves as I expect in Mozilla and Opera, but there are two glaring differences in IE (5.5): 1) The anchors...
6
by: harry | last post by:
Hi, I have a program that runs on multiple client pc's. Occasionally one or more of those pc's use VPN to connect to another corporate network. When using VPN they need to set proxy server in...
4
by: Patrik | last post by:
Hi, I need help on this one. For the past two days, whenever I make a modification to a stored procedure using enterprise manager (Apply), the stored procedure stops working. If I copy it...
8
by: nick | last post by:
I have a problem and I've been using a cheezy work around and was wondering if anyone else out there has a better solution. The problem: Let's say I have a web application appA. Locally, I set...
3
by: Jan Krouwer | last post by:
I have a problem that shows up only on some systems - the toolbar text in buttons is not visible (vb.net 2003 app, 1.1 framework). As a workaround, I changed the textalign property to "right". This...
1
by: rory | last post by:
Have the following setting in my app.config: <setting name="Scenes" serializeAs="Xml"> <value> <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"...
5
by: Segfahlt | last post by:
I need a little help here please. I have 2 win forms user controls in 2 different projects that I'm hosting in 2 different virtual directories. The controls have been test and operate okay in...
5
by: snow | last post by:
Hi All, ToOADate can change a date value to a double value, but if I change the Regional and Lauguage setting in control panel, for example, change English(US) to English(Australia) , the same...
3
by: Dreea | last post by:
Hello i have a .netapplication that runs with no problem when launched from the local machine, but when i try to run the same executable from the network the applications doesn't start. I suppose...
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...
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...

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.