Ejemplos en Javascript

Editor de colores

Elegir el color y el tono deseados mediante valores hexadecimales.

<HTML>
<HEAD>

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

<SCRIPT LANGUAGE = "JavaScript">

hexstr = '0123456789ABCDEF'

function doParse(s) {
        x = parseInt(s)
        if ((x<0) || (x>255)) {
                alert('Numbers must be within 0 and 255')
                return -1
        }
        return x
}//doParse()

function doConvert(x) {
        s = ''
        x1 = hexstr.charAt(Math.floor(x/16))
        x2 = hexstr.charAt(x % 16)
        s = s + x1 + x2
        return s
}//doConvert()
function doChange() {
        t = document.form1
        var r, g, b
        r = doParse(t.RI.value)
        g = doParse(t.GI.value)
        b = doParse(t.BI.value)
        if (r==-1) { t.RI.value=0 ; return true }
        if (g==-1) { t.GI.value=0 ; return true }
        if (b==-1) { t.BI.value=0 ; return true }
        s = '#' + doConvert(r) + doConvert(g) + doConvert(b)
        document.bgColor = s
        t.out.value = s
        return true
} //doChange()
function doAlter(dst,val) {
        var x = doParse(dst.value)
        if ( x != -1 )
                dst.value = ((x+val<0)||(x+val>255)) ? ((x+val+255)%255) : (x + val)
        doChange()
        return false
}

</SCRIPT>


</HEAD>

<BODY bgcolor="white">

 
<FORM NAME="form1">
<center>
<table>
<tr><td>Red:<td>Green:<td>Blue:<td>RGB:
<tr>
<td align="center"><a href="JavaScript:alert('Do not click, simply roll over these areas.')" onMouseover="doAlter(document.form1.RI,1);">+</a>
<td align="center"><a href="JavaScript:alert('Do not click, simply roll over these areas.')" onMouseover="doAlter(document.form1.GI,1);">+</a>
<td align="center"><a href="JavaScript:alert('Do not click, simply roll over these areas.')" onMouseover="doAlter(document.form1.BI,1);">+</a>
<tr>
<td><INPUT TYPE="text" NAME="RI" value="0" SIZE="4" onChange="doChange()">
<td><INPUT TYPE="text" NAME="GI" value="0" SIZE="4" onChange="doChange()">
<td><INPUT TYPE="text" NAME="BI" value="0" SIZE="4" onChange="doChange()">
<td><INPUT TYPE="text" NAME="out" value="#FFFFFF" SIZE="8">
<tr>
<td align="center"><a href="JavaScript:alert('Do not click, simply roll over these areas.')" onMouseover="doAlter(document.form1.RI,-1);">-</a>
<td align="center"><a href="JavaScript:alert('Do not click, simply roll over these areas.')" onMouseover="doAlter(document.form1.GI,-1);">-</a>
<td align="center"><a href="JavaScript:alert('Do not click, simply roll over these areas.')" onMouseover="doAlter(document.form1.BI,-1);">-</a>
</table>
</FORM>

</body>
</html>

Background y fondo