Dynamic table data background color in NN

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael McClune

    Dynamic table data background color in NN

    Is it possible to change a <TD> background color on the fly with NN? There
    are a long list of members info that I want to alternate the background
    color of.
    I have tried calling variation of the shown function "somefunction(t his)"
    from within each <TD> and accessing the <TD> style to no avail.


    This works in IE:

    <script type="text/JavaScript" language="JavaS cript" >
    <!--
    function colortable(){
    for (var i=0; i < pmdtable.rows.l ength; i += 2){
    member[i].className = "white_bg";
    // -or- member[i].bgcolor = "white"
    }
    }
    // end javascript -->
    </script>

    <body onload = "colortable ()">
    <table id="pmdtable">
    <tr>
    <td id="member">
    name
    whatever
    </td>
    ...
    ...
    </tr>
    </table>

    Thanks

    Mike


  • Randy Webb

    #2
    Re: Dynamic table data background color in NN

    Michael McClune wrote:
    [color=blue]
    > Is it possible to change a <TD> background color on the fly with NN? There
    > are a long list of members info that I want to alternate the background
    > color of.
    > I have tried calling variation of the shown function "somefunction(t his)"
    > from within each <TD> and accessing the <TD> style to no avail.
    >
    >
    > This works in IE:
    >
    > <script type="text/JavaScript" language="JavaS cript" >
    > <!--
    > function colortable(){
    > for (var i=0; i < pmdtable.rows.l ength; i += 2){
    > member[i].className = "white_bg";[/color]

    In both of the above lines, you are relying on the IE shortcut method of
    obtaining a reference to an object.
    [color=blue]
    > // -or- member[i].bgcolor = "white"
    > }
    > }
    > // end javascript -->
    > </script>
    >
    > <body onload = "colortable ()">
    > <table id="pmdtable">
    > <tr>
    > <td id="member">
    > name
    > whatever
    > </td>
    > ...
    > ...
    > </tr>
    > </table>[/color]

    Which version of Netscape? How you do it in Netscape 6/7 is totally
    different than how you would do it in Netscape 4.xx



    --
    Randy

    Comment

    • Michael McClune

      #3
      Re: Dynamic table data background color in NN

      I have Netscape 7.1 and I need this to work with as broad a range of
      browsers as possible. Interestingly enough I tested for each of
      document.getEle mentById, document.all and document.layers with simple if
      /else if... and alert() if OK script. IE supported document.all, NN didn't
      seem to support to any of these.

      Regards

      "Randy Webb" <hikksnotathome @aol.com> wrote in message
      news:DaSdnfThJq tJzJ7dRVn-vw@comcast.com. ..[color=blue]
      > Michael McClune wrote:
      >[color=green]
      > > Is it possible to change a <TD> background color on the fly with NN?[/color][/color]
      There[color=blue][color=green]
      > > are a long list of members info that I want to alternate the background
      > > color of.
      > > I have tried calling variation of the shown function[/color][/color]
      "somefunction(t his)"[color=blue][color=green]
      > > from within each <TD> and accessing the <TD> style to no avail.
      > >
      > >
      > > This works in IE:
      > >
      > > <script type="text/JavaScript" language="JavaS cript" >
      > > <!--
      > > function colortable(){
      > > for (var i=0; i < pmdtable.rows.l ength; i += 2){
      > > member[i].className = "white_bg";[/color]
      >
      > In both of the above lines, you are relying on the IE shortcut method of
      > obtaining a reference to an object.
      >[color=green]
      > > // -or- member[i].bgcolor = "white"
      > > }
      > > }
      > > // end javascript -->
      > > </script>
      > >
      > > <body onload = "colortable ()">
      > > <table id="pmdtable">
      > > <tr>
      > > <td id="member">
      > > name
      > > whatever
      > > </td>
      > > ...
      > > ...
      > > </tr>
      > > </table>[/color]
      >
      > Which version of Netscape? How you do it in Netscape 6/7 is totally
      > different than how you would do it in Netscape 4.xx
      >
      >
      >
      > --
      > Randy
      >
      >[/color]


      Comment

      • kaeli

        #4
        Re: Dynamic table data background color in NN

        In article <7nRMb.30701$I0 5.523259@twiste r.tampabay.rr.c om>,
        mmcclune@cfl.rr .com enlightened us with...[color=blue]
        > I have Netscape 7.1 and I need this to work with as broad a range of
        > browsers as possible.[/color]

        It is VERY hard to get dynamic page elements in old browsers, like NN4x.
        It is impossible in some.
        [color=blue]
        > Interestingly enough I tested for each of
        > document.getEle mentById, document.all and document.layers with simple if
        > /else if... and alert() if OK script. IE supported document.all, NN didn't
        > seem to support to any of these.
        >[/color]

        Sure it deos. I do it all the time.
        if (document.getEl ementById && !document.all)
        {
        // netscape 6,7,Mozilla, etc
        alert("NN 7");
        }
        else if (document.all && document.getEle mentById)
        {
        // new IE, opera, etc
        alert("IE 6");
        }
        else if (document.all && !document.getEl ementById)
        {
        // old IE
        alert("IE 4");
        }
        else if (document.layer s)
        {
        // old NN
        alert("NN 4");
        }



        --
        --
        ~kaeli~
        No one is listening until you make a mistake.



        Comment

        • Michael McClune

          #5
          Re: Dynamic table data background color in NN

          For NN is there an array of, in this case, "members" I can iterate over as I
          did with the IE script e.g. member[#].className?

          "kaeli" <tiny_one@NOSPA M.comcast.net> wrote in message
          news:MPG.1a6db9 0fe3df7921989ac 0@nntp.lucent.c om...[color=blue]
          > In article <7nRMb.30701$I0 5.523259@twiste r.tampabay.rr.c om>,
          > mmcclune@cfl.rr .com enlightened us with...[color=green]
          > > I have Netscape 7.1 and I need this to work with as broad a range of
          > > browsers as possible.[/color]
          >
          > It is VERY hard to get dynamic page elements in old browsers, like NN4x.
          > It is impossible in some.
          >[color=green]
          > > Interestingly enough I tested for each of
          > > document.getEle mentById, document.all and document.layers with simple if
          > > /else if... and alert() if OK script. IE supported document.all, NN[/color][/color]
          didn't[color=blue][color=green]
          > > seem to support to any of these.
          > >[/color]
          >
          > Sure it deos. I do it all the time.
          > if (document.getEl ementById && !document.all)
          > {
          > // netscape 6,7,Mozilla, etc
          > alert("NN 7");
          > }
          > else if (document.all && document.getEle mentById)
          > {
          > // new IE, opera, etc
          > alert("IE 6");
          > }
          > else if (document.all && !document.getEl ementById)
          > {
          > // old IE
          > alert("IE 4");
          > }
          > else if (document.layer s)
          > {
          > // old NN
          > alert("NN 4");
          > }
          >
          >
          >
          > --
          > --
          > ~kaeli~
          > No one is listening until you make a mistake.
          > http://www.ipwebdesign.net/wildAtHeart
          > http://www.ipwebdesign.net/kaelisSpace
          >
          >[/color]


          Comment

          • kaeli

            #6
            Re: Dynamic table data background color in NN

            In article <LVUMb.34123$I0 5.546364@twiste r.tampabay.rr.c om>,
            mmcclune@cfl.rr .com enlightened us with...[color=blue]
            > For NN is there an array of, in this case, "members" I can iterate over as I
            > did with the IE script e.g. member[#].className?
            >[/color]

            For NN4?
            I don't think so. NN4 only did layers, and that was a huge pain. Most of
            us have just stopped programming for it and let our scripts degrade so
            that the stuff doesn't crash old browsers.
            I don't do commercial sites, so I have a caveat that my users must use
            NN6+ if I have need of DHTML. My internet sites don't do anything fancy
            that won't work in all browsers (as a requirement for function; they may
            look prettier).

            NN6+ can do the same DOM things as IE, for the most part, but your
            script used IE only shortcuts, not DOM methods.

            The standard is that all ids on a page should be unique.
            NAME your cells the same name, then use getElementsByNa me to get all the
            tags and style as appropriate. Note that getElementsByNa me is DOM only
            and will not work in old browsers, so the check
            if (document.getEl ementsByName)
            should be used to avoid crashes.

            I think you can say
            document.getEle mentsByName("me thod")[i].className=clas s
            but have not tried it. If that works, you can just use a loop to change
            the class for all elements with that name.

            So...not sure, but try this. (IE5+/NN6+/compatible)
            <script type="text/javascript" language="javas cript" >
            function colortable(){
            var members = document.getEle mentsByName("me mber")
            for (var i=0; i < members.length; i += 2){
            members[i].className = "white_bg";
            }
            }
            </script>

            <body onload = "colortable ()">
            <table id="pmdtable">
            <tr>
            <td name="member">
            name
            whatever
            </td>
            ...
            ...
            </tr>
            </table>

            --
            --
            ~kaeli~
            Murphy's Law #2030: If at first you don't succeed, destroy
            all evidence that you tried.



            Comment

            • Michael McClune

              #7
              Re: Dynamic table data background color in NN

              Thank you kaeli. It should be noted that the script does not have to use IE
              shortcuts but I'm getting older and lazier, and I use IE for which the
              script worked... until I fetched Netscape. I suppose those folks with NN may
              just have to look at plain blue rows. I will give your ideas a try.

              It is unfortunate that 57% of those visiting the site use NN 4 (grin)

              Old minds are like old horses; you must exercise them if you wish to keep
              them in working order.

              - John Quincy Adams

              "kaeli" <tiny_one@NOSPA M.comcast.net> wrote in message
              news:MPG.1a6e0a 4e1c12c4e9989ac b@nntp.lucent.c om...[color=blue]
              > In article <LVUMb.34123$I0 5.546364@twiste r.tampabay.rr.c om>,
              > mmcclune@cfl.rr .com enlightened us with...[color=green]
              > > For NN is there an array of, in this case, "members" I can iterate over[/color][/color]
              as I[color=blue][color=green]
              > > did with the IE script e.g. member[#].className?
              > >[/color]
              >
              > For NN4?
              > I don't think so. NN4 only did layers, and that was a huge pain. Most of
              > us have just stopped programming for it and let our scripts degrade so
              > that the stuff doesn't crash old browsers.
              > I don't do commercial sites, so I have a caveat that my users must use
              > NN6+ if I have need of DHTML. My internet sites don't do anything fancy
              > that won't work in all browsers (as a requirement for function; they may
              > look prettier).
              >
              > NN6+ can do the same DOM things as IE, for the most part, but your
              > script used IE only shortcuts, not DOM methods.
              >
              > The standard is that all ids on a page should be unique.
              > NAME your cells the same name, then use getElementsByNa me to get all the
              > tags and style as appropriate. Note that getElementsByNa me is DOM only
              > and will not work in old browsers, so the check
              > if (document.getEl ementsByName)
              > should be used to avoid crashes.
              >
              > I think you can say
              > document.getEle mentsByName("me thod")[i].className=clas s
              > but have not tried it. If that works, you can just use a loop to change
              > the class for all elements with that name.
              >
              > So...not sure, but try this. (IE5+/NN6+/compatible)
              > <script type="text/javascript" language="javas cript" >
              > function colortable(){
              > var members = document.getEle mentsByName("me mber")
              > for (var i=0; i < members.length; i += 2){
              > members[i].className = "white_bg";
              > }
              > }
              > </script>
              >
              > <body onload = "colortable ()">
              > <table id="pmdtable">
              > <tr>
              > <td name="member">
              > name
              > whatever
              > </td>
              > ...
              > ...
              > </tr>
              > </table>
              >
              > --
              > --
              > ~kaeli~
              > Murphy's Law #2030: If at first you don't succeed, destroy
              > all evidence that you tried.
              > http://www.ipwebdesign.net/wildAtHeart
              > http://www.ipwebdesign.net/kaelisSpace
              >
              >[/color]


              Comment

              • kaeli

                #8
                Re: Dynamic table data background color in NN

                In article <zwZMb.7907$873 .185383@twister .tampabay.rr.co m>,
                mmcclune@cfl.rr .com enlightened us with...[color=blue]
                > Thank you kaeli. It should be noted that the script does not have to use IE
                > shortcuts but I'm getting older and lazier, and I use IE for which the
                > script worked... until I fetched Netscape. I suppose those folks with NN may
                > just have to look at plain blue rows.[/color]

                Yes, for NN4.
                Don't worry, they're used to it. *smirk*
                [color=blue]
                >
                > Old minds are like old horses; you must exercise them if you wish to keep
                > them in working order.[/color]

                How true!
                hehe


                If you really want to cater to the NN4 folks, what you'd have to do is
                dynamically write the table to a layer with document.write statements.
                However, the less people cater to them, the more they'll upgrade,
                assuming they have the option. ;)


                --
                --
                ~kaeli~
                Why do people who know the least know it the loudest?



                Comment

                Working...