Color Changing
Changing the color of a box by entering values within input field
by Joe Saad
HTML
<div id="color-bx"></div>
<input type="text" id="color-val" maxlength="6" />
<button type="button"> change color</button>
CSS
#color-bx {width:100px; height:100px; border:1px solid #000;position:absolute; left:100px; top:100px;}
#color-val {float:left;}
JavaScript
$(document).ready(function() {
$('input').keyup(function() {
if (this.value.length == 6) {
var myInput = $('input').val();
R = parseInt(myInput.substring(0, 2), 16);
G = parseInt(myInput.substring(2, 4), 16);
B = parseInt(myInput.substring(4, 6), 16);
$('div').css('background-color', "rgb(" + R + "," + G + "," + B + ")");
}
});
});