How to change table border from javascript?

Discussion in 'Javascript' started by Harry, Oct 21, 2003.

  1. Harry

    Harry Guest

    Whats wrong with this?

    top.document.frmMain.tabMain.border = "1";

    thanks
     
    Harry, Oct 21, 2003
    #1
    1. Advertisements

  2. It has no context.

    Richard.
     
    Richard Cornford, Oct 21, 2003
    #2
    1. Advertisements

  3. Harry

    Harry Guest

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

    thanks
     
    Harry, Oct 21, 2003
    #3
  4. Harry

    kaeli Guest

    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
    -------------------------------------------------
     
    kaeli, Oct 21, 2003
    #4
  5. Harry

    Harry Guest

    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
     
    Harry, Oct 21, 2003
    #5
  6. Harry

    kaeli Guest

    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
    -------------------------------------------------
     
    kaeli, Oct 21, 2003
    #6
  7. That is unlikely to work, since "1" is not a valid CSS value for the
    border property.
    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
     
    Lasse Reichstein Nielsen, Oct 21, 2003
    #7
  8. Harry

    kaeli Guest



    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
    -------------------------------------------------
     
    kaeli, Oct 21, 2003
    #8
  9. 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");
    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
     
    Lasse Reichstein Nielsen, Oct 21, 2003
    #9
  10. Harry

    kaeli Guest

    Thanks!

    -------------------------------------------------
    ~kaeli~
    Jesus saves, Allah protects, and Cthulhu
    thinks you'd make a nice sandwich.
    http://www.ipwebdesign.net/wildAtHeart
    http://www.ipwebdesign.net/kaelisSpace
    -------------------------------------------------
     
    kaeli, Oct 22, 2003
    #10
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.