Html:
<! DOCTYPEHtml>
<Html>
<Head>
<Metahttp-equiv="Content-type"Content="Text/html; Charset=utf-8 "/>
<Title>RGB Color Conversion </Title>
<ScriptLanguage="JavaScript" >
functionShowrgb (obj) {
Where red, green, and blue are the name values for the input box
VarORed=Obj.red.value;
VarOgreen=Obj.green.value
VarOblue=Obj.blue.value;
Converts RGB to 16 hex value, string
Ohexcode="#"+Tohex (oRed)+Tohex (Ogreen)+Tohex (Oblue);
VarOdiv= document.getElementById ("Div");
The background color of the div =name the value of the =16 background color for the value of the Hexval input box
ODiv.style.background=Obj.hexval.value= Ohexcode;
}
functionTohex (D) {
If the input is not a number
if (IsNaN (D)) {
D=0;
}
16 Binary Conversion method
VarN= new Number (D).ToString (16);
Return (N.length==1?"0"+N:n);
}
</Script>
</Head>
<Body>
<Formstyle="Border1PX Blue solid;">
<B>Please enter an RGB color value (0 to 255) </b><Br>
Red: <InputType="Text"Name="Red"Size="5" ><Br>
Green: <InputType="Text"Name="Green"Size="5" ><Br>
Blue: <InputType="Text"Name="Blue"Size="5" ><Br>
<buttononclick="Showrgb (This.ParentNode)"Type="Button" >Show Hex #</Button>
Hex value is: <InputType="Text"Name="Hexval"Size="7" >
</Form>
<DivId="Div"style="margin: +px; Width: px; Height: px; border: 1px solid red; ></div>
</body>
</html>
Result
Online input RGB Change background color