Ejemplos en Javascript

Editor para colores de fondo

Este script permite elegir el color de fondo haciendo referencia a valores hexadecimales.

<HTML>
<HEAD>

<TITLE>Ejemplos Javascript: ejemplo pr???¡ctico </TITLE>

<Script Language="JavaScript">
<!-- Hiding
/*      Script by Lefteris Haritou
                21/05/1997      
        http://www.geocities.com/~lef
        Please Keep The Credit Above
        (No copyrights, but be fair)
*/

var red=0;
var green=0;
var blue=0;
var value=0;
var convert = new Array()
var hexbase= new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F");

for (x=0; x<16; x++){
for (y=0; y<16; y++){
convert[value]= hexbase[x] + hexbase[y];
value++;
}
}

function clear(){
document.color.bl.value= blue;
document.color.rd.value= red;
document.color.gr.value= green;
}

function display(){
redx = convert[red]
greenx = convert[green]
bluex = convert[blue]
var rgb = "#"+redx+greenx+bluex;
document.color.rgbdspl.value= rgb;
document.bgColor =rgb;
}

function upred(x){
if ((red+x)<=255)
red+=x
document.color.rd.value= red;
display()
}

function downred(x){
if ((red-x)>=0)
red-=x
document.color.rd.value= red;
display()
}

function upgreen(x){
if ((green+x)<=255)
green+=x
document.color.gr.value= green;
display()
}

function downgreen(x){
if ((green-x)>=0)
green-=x
document.color.gr.value= green;
display()
}

function upblue(x){
if ((blue+x)<=255)
blue+=x
document.color.bl.value= blue;
display()
}

function downblue(x){
if ((blue-x)>=0)
blue-=x
document.color.bl.value= blue;
display()
}

// done hiding -->
</Script>


</HEAD>

<BODY bgcolor="white" onLoad="clear();display()">

 
<CENTER>
<FORM Name="color">
<TABLE>

<TR Align="Center"><TD><INPUT NAME="red" type="button" VALUE=" +50 " onclick="upred(50)"></TD><TD><INPUT NAME="red" type="button" VALUE=" + + " onclick="upred(10)"></TD><TD><INPUT NAME="red" type="button" VALUE=" + " onclick="upred(1)">
</TD><TD><Font Color="#FF0000" size=+3>RED</font></TD>
<TD><INPUT NAME="red-" type="button" VALUE=" - " onclick="downred(1)"></TD><TD><INPUT NAME="red-" type="button" VALUE=" - - " onclick="downred(10)"></TD><TD><INPUT NAME="red-" type="button" VALUE=" -50 " onclick="downred(50)"></TD>
<TD><Input type="text" Name="rd" Size=3></TD></TR>


<TR Align="Center"><TD><INPUT NAME="green" type="button" VALUE=" +50 " onclick="upgreen(50)"></TD><TD><INPUT NAME="green" type="button" VALUE=" + + " onclick="upgreen(10)"></TD><TD><INPUT NAME="green" type="button" VALUE=" + " onclick="upgreen(1)"></TD>
<TD><Font Color="#00FF00" size=+3>GREEN</font></TD>
<TD><INPUT NAME="green-" type="button" VALUE=" - " onclick="downgreen(1)"></TD><TD><INPUT NAME="green-" type="button" VALUE=" - - " onclick="downgreen(10)"></TD><TD><INPUT NAME="green-" type="button" VALUE=" -50 " onclick="downgreen(50)"></TD>
<TD><Input type="text" Name="gr" Size=3></TD></TR>


<TR Align="Center"><TD><INPUT NAME="blue" type="button" VALUE=" +50 " onclick="upblue(50)"></TD><TD><INPUT NAME="blue" type="button" VALUE=" + + " onclick="upblue(10)"></TD><TD><INPUT NAME="blue" type="button" VALUE=" + " onclick="upblue(1)"></TD>
<TD><Font Color="#0000FF" size=+3>BLUE</font></TD>
<TD><INPUT NAME="blue-" type="button" VALUE=" - " onclick="downblue(1)"></TD><TD><INPUT NAME="blue-" type="button" VALUE=" - - " onclick="downblue(10)"></TD><TD><INPUT NAME="blue-" type="button" VALUE=" -50 " onclick="downblue(50)"></TD>
<TD><Input type="text" Name="bl" Size=3></TD></TR>

</TABLE>
<Input type="text" Name="rgbdspl" Size=7>
</FORM>
</CENTER>



</body>
</html>

Background y fondo