Choose Background Color

[Total: 1    Average: 5/5]

This will change the background color to whatever you specify.

Body Code:

<script language="JavaScript">
<!--
  var r=0, g=0, b=0, rgb=0, inc=0, cnt=0, cnt2=0;
  var part1 = "", part2 = "";
  function makeArray(n) {
    // REMOVED THIS LINE FOR NN3.0: this.length = n;

    // Create the array, starting at position 1 in this
    // instance, although it could be 0 just as long as
    // you alter the hexTable definition to start at 0

    for (var x=1; x <=n; x++)
        this[x] = 0; 
    return(this);
  }
  hexTable = makeArray(16);
  // Col:Row
  hexTable[1]  = "00:00";
  hexTable[2]  = "10:01";
  hexTable[3]  = "20:02";
  hexTable[4]  = "30:03";
  hexTable[5]  = "40:04";
  hexTable[6]  = "50:05";
  hexTable[7]  = "60:06";
  hexTable[8]  = "70:07";
  hexTable[9]  = "80:08";
  hexTable[10] = "90:09";
  hexTable[11] = "A0:0A";
  hexTable[12] = "B0:0B";
  hexTable[13] = "C0:0C";
  hexTable[14] = "D0:0D";
  hexTable[15] = "E0:0E";
  hexTable[16] = "F0:0F";

  function seeColors() {
    // Validate the form input:
    ok = true;
    if (document.forms[0].red.value > 255)   { ok=false }
    if (document.forms[0].green.value > 255) { ok=false }
    if (document.forms[0].blue.value > 255)  { ok=false }
    if (!ok) {
       document.forms[0].rgbval.value = "";
       alert("Error: value greater than 255 detected.");
    }
    else {
       r = DecToHex(document.forms[0].red.value);
       g = DecToHex(document.forms[0].green.value);
       b = DecToHex(document.forms[0].blue.value);
       rgb = r + g + b;
       document.bgColor = "#" + rgb;
       document.forms[0].rgbval.value = "#" + rgb
    }
  }
 
  function DecToHex(decval) {
    inc = 0;
    cnt = 1;
    while ((inc += 16) <= decval) {
         cnt ++;
    }
    inc  = inc - 16;
    cnt2 = Math.abs(decval - inc) + 1;
    part1 = hexTable[cnt].substring(0,2);
    part2 = hexTable[cnt2].substring(3,5);
    // Trim off any trailing and leading 0's
    if (part1.substring(2,1) == "0") {
       part1 = part1.substring(0,1);
    }
    if (part2.substring(0,1) == "0") {
       part2 = part2.substring(2,1);
    }
    return(part1+part2);
  }      
//-->
</script>
<tt>
<basefont size=4>
<form>
BACKGROUND (HEX) <input name="rgbval" size=8>&nbsp&nbsp;<br>
R: <input name="red"   size=5 value=00>&nbsp;
G: <input name="green" size=5 value=00>&nbsp;
B: <input name="blue"  size=5 value=00><p>
<input type="button" 
       value="See Results"
       onClick="seeColors()"></p>
</form>
</tt>

Times Viewed: 3

Leave a Reply

Your email address will not be published. Required fields are marked *