JavaScript Scripts





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
Free Java Script Codes
Javascript List All
Slide Show Slide Show
Ad Display Ad Display
Image Effect Image Effect
Animated Image Effects Animated Image Effects
Form Validation Form Validation
Color Picker Tool Color Picker Tool
Formatting Forms Formatting Forms
Select All Select All
Dynamic Form Select Dynamic Form select
Dynamic Color Dynamic Color
Calendar Script Calendar
Textbox Counter Textbox Counter
Alphanumeric Alphanumeric
Date Time Script Date & Time
Stop Watch Script Stop Watch script
Delete Repeated Values Delete Repeated Values
Pagination Pagination
Random Generator Random Generator
Animated Text Animated Text
Cursor Position Cursor Position
User Info Window / User Info
Security Security / Authenticate
Bookmark Bookmark
Mouse Effects Mouse Effects
Title Bar Title Bar
Status Bar Status Bar
Country List Country List
Free Games Free Games
Calculators Calculators
 




Javascript Background Color Changer


About
 This Javascript function helps you to change background color of the web page or html table.


Features
 a) This javascript color changer is used dynamically to change the color of background.
 b) You can also change the background color of the html table.
 c) You can select color from color palette.

Preview
Preview to change bgcolor of HTML Table:

Preview to change background color of the web page Demo


Code
 Javascript Code
<!-- Script by hscripts.com -->
<script type="text/javascript">
function clicked(gg,rr,bb)
{
	var hex='#'+deciToHex(gg)+deciToHex(rr)+deciToHex(bb);
        document.body.style.backgroundColor=hex;
//      document.getElementById('tbprev').style.backgroundColor=hex;
}
function getHexNum(num)
{
	ar1=new Array('0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15');
	ar2=new Array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
	if(num>15)
		return num;
	else
	{
		red=ar2[num];
		return red;
	}
}
function deciToHex(arg)
{
	res2=999;
	args=arg;
	while(args>15)
	{
		arg1=parseInt(args/16);
		arg2=args%16;
		arg2=getHexNum(arg2);
		args=arg1;
		if(res2==999)
			res2=arg2.toString();
		else
			res2=arg2.toString()+res2.toString();
	}
	if(args<16 && res2 != 999)
	{
		def=getHexNum(args);
		res2=def+res2.toString();
	}
	else if(res2==999)
	{
		if(args<16)
			res2=getHexNum(args);
		else
			res2=1;
	}
	if(res2.length==1)
		res2="0"+res2;
	return res2;
}
</script>


 HTML Code
<style type="text/css">
.tab{border: 1px inset black; background-color: black;}
</style>
<form name=colchanger>
<table style="width:100%;" id='tbprev'>
<tr><td>
<table class=tab cellpadding=0 cellspacing=0>
<script type="text/javascript">
	for(i=0;i<=256;i+=18)
	{
	if(i==252) i=255;
	document.write("<tr>");
	for(j=0;j<=256;j=j+51)
	{
		for(k=0;k<=256;k=k+51)
		{
		document.write("<td onclick='clicked("+i+","+j+","+k+")' \
		style=\"border: 1px inset black; width:10px; \
		height: 3px; font-size: 6px; background-color: rgb("+i+","+j+","+k+");\""+"> </td>");
		}
	}
	document.write("</tr>");
	}
</script>
</table>
</td></tr>
</table>
</form>


Get free version without ©copyright link for just 5 price

For customization of this script or any script development, contact us at support@hscripts.com


Usage
 a) Copy the above code into your file.

 b) Use the following function, inorder to view background color change for a table.
      function clicked(gg,rr,bb)
      {
        var hex='#'+deciToHex(gg)+deciToHex(rr)+deciToHex(bb);
        document.getElementById('tbprev').style.backgroundColor=hex;
      }


 c) Set the table-id as 'tbprev' inorder to change the background color for a table.

 d) Use the following function, inorder to view background color change for a page.
      function clicked(gg,rr,bb)
      {
         var hex='#'+deciToHex(gg)+deciToHex(rr)+deciToHex(bb);
         document.body.style.backgroundColor=hex;
      }


 e) You can use any of the above function to view background-color change.



License
- The javascript (misspelled as java script) is given under GPL License
- i.e. Free use for those who use the codes as it is.
- Free, if your modification does not remove our copyright information and links.
- Click Here for detailed license information.
- You can purchase the script if your requirements does not meet our GPL License terms.
Other Links

web hosting