How to change table border from javascript?

K

kaeli

how would I do it then? - what am I missing?

You're missing the rest of the code and an explanation of what doesn't
work, what you want, and target browsers, if any.

Context = tell us what the heck you want.

-------------------------------------------------
~kaeli~
Jesus saves, Allah protects, and Cthulhu
thinks you'd make a nice sandwich.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
 
H

Harry

sorry, target browsers are ie 5.5 & netscape 7

I want the user to be able to click on a checkbox which will using
javascript show/hide the border of a table

thanks

harry
 
K

kaeli

sorry, target browsers are ie 5.5 & netscape 7

I want the user to be able to click on a checkbox which will using
javascript show/hide the border of a table

thanks

If the table is named tabMain (<table id="tabMain">)

if (document.getElementById && document.getElementById("tabMain").style)
{
document.getElementById("tabMain").style.border = "1";
}
else alert("You need a better browser.");


You don't need "top" unless you're using frames, in which case you need
the frame name as defined in the frameset.

if (top.frames["frameName"].document.getElementById && top.frames
["frameName"].document.getElementById("tabMain").style)
{
top.frames["frameName"].document.getElementById
("tabMain").style.border = "1";
}
else alert("You need a better browser.");

-------------------------------------------------
~kaeli~
Jesus saves, Allah protects, and Cthulhu
thinks you'd make a nice sandwich.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
 
L

Lasse Reichstein Nielsen

kaeli said:
If the table is named tabMain (<table id="tabMain">)

if (document.getElementById && document.getElementById("tabMain").style)
{
document.getElementById("tabMain").style.border = "1";

That is unlikely to work, since "1" is not a valid CSS value for the
border property.
You don't need "top" unless you're using frames, in which case you need
the frame name as defined in the frameset.

The original poster wrote this "top.document.frmMain.tabMain.border". I
assume "frmMain" is a frame name. I.e., something like:

var frm = top.frames['frmMain'];
if (frm && frm.document.getElementById) {
var elem = frm.document.getElementById("tabMain");
if (elem && elem.style) {
elem.style.border = "1px solid black";
}
}

/L
 
K

kaeli

[email protected] enlightened us said:
That is unlikely to work, since "1" is not a valid CSS value for the
border property.



How WOULD you set the border to 1? I stick to DIVs mostly, which would
be like...
document.getElementById("tabMain").style.border="thin solid black";


I don't think that would set the borders for the cells, though, just the
table. It would look different than having border be "1" in the table
def...

-------------------------------------------------
~kaeli~
Jesus saves, Allah protects, and Cthulhu
thinks you'd make a nice sandwich.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
 
L

Lasse Reichstein Nielsen

kaeli said:
How WOULD you set the border to 1? I stick to DIVs mostly, which would
be like...
document.getElementById("tabMain").style.border="thin solid black";

If you want to simulate the border attribute, the most likely way is:
document.getElementById("tabMain").border=1;
If that doesn't work, you can try:
document.getElementById("tabMain").setAttribute("border","1");
I don't think that would set the borders for the cells, though, just the
table. It would look different than having border be "1" in the table
def...

Yes. I never used the border attribute, so I would go for a CSS solution:

<style type="text/css">
table {
border-collapse:collapse;
}
.borderTable td {
border: 1px solid black;
}
</style>

and then set the className instead of the border property:

document.getElementById("tabMain").className="borderTable";

To remove the border, you would then do:

document.getElementById("tabMain").className="";

/L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top