Results 1 to 2 of 2

Thread: Font and Table color settings

  1. #1

    Thread Starter
    Hyperactive Member oyad's Avatar
    Join Date
    Feb 2003
    Location
    PhoxWare MicroSystems
    Posts
    463

    Lightbulb Font and Table color settings

    hey guys, plz how can i set FONT color, TABLE bgcolor and its bordercolor randomly, may be using Javascript so that the font and table will have different color settings each time the HTML page is loaded

    <font color=???> where ??? will not be fixed so that i can randomly generate a color value for it.
    Oyad
    Nobody is smarter than all of us!

  2. #2
    Fanatic Member Psyrus's Avatar
    Join Date
    Jul 2000
    Location
    NJ
    Posts
    602

    Re: Font and Table color settings

    HTML Code:
    <html>
    <head>
    <title>Random Colors</title>
    
    <style type = "text/css">
    body {color:red;}
    table {background:blue; border-style: solid; border-color: red;}
    </style>
    
    <script type = "text/javascript">
    
    function randomColor(){
    
      r = Math.round(Math.random() * 255);
      g = Math.round(Math.random() * 255);
      b = Math.round(Math.random() * 255);
    
      base = r / 16;
      rem = r % 16;
      base = base - (rem / 16);
      baseR = ConvertToHex(base);
      remR = ConvertToHex(rem);
    
      base = g / 16;
      rem = g % 16;
      base = base - (rem / 16);
      baseG = ConvertToHex(base);
      remG = ConvertToHex(rem);
    
      base = b / 16;
      rem = b % 16;
      base = base - (rem / 16);
      baseB = ConvertToHex(base);
      remB = ConvertToHex(rem);
    
      hexnum = '#' + baseR +remR + baseG + remG + baseB + remB;
    
      return hexnum;
    
    }//end randomColor
    
    function ConvertToHex(num) {
      if((num >= 0) && (num <= 9))
        return num;
      else {
        switch(num) {
          case 10: return "A"; 
          case 11: return "B";  
          case 12: return "C";  
          case 13: return "D";  
          case 14: return "E";  
          case 15: return "F";  
          }//end switch
       }//end else
    }//end ConvertToHex
    
    
    function changeTableColor(){
      tblMain.style.borderColor = randomColor();
    }
    
    function changeFontColor(){
      tblMain.style.color = randomColor();
    }
    
    </script>
    
    </head>
    
    <body onload = "changeFontColor();changeTableColor();">
    
    <h1>Random Colors</h1>
    </ br>
    <table ID = "tblMain">
    <tr><td>table cell</td></tr>
    </table>
    </body>
    </html>
    Chris

    VB 6.0 Calendar App Video Gamers Group
    Don't forget to rate people if they helped you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width