H I O X INDIA
FREE Javascript
Google
Web hscripts.com
 HOME  ||  Scripts  ||  Purchase  ||  Tutorials  ||  Images  ||  Tools  ||  Directories 
  :-)  Send Page   :-)   Feedback   :-)   Register   :-)   Links   :-)   Support   :-)   Bookmarks :-)  
 Forums   Hosting   Internet Stats   Easy Calculation   FUN Games 

Java Script Source
List All
Date & Time
Calendar
Stop Watch script
Slide Show
Image Effect
Mouse Effects
Color Picker Tool
Dynamic Color
Random Generator
Select All
Form Validation
Textbox Counter
Dynamic Form select
Bookmark
Window / User Info
Security / Authenticate
Status Bar
Title Bar
Cursor Position
Country List
Calculators
Delete Repeated Values
Alphanumeric
Free Games





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 your 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 language="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>
.tab{border: 1px inset black; background-color: black;}
</style>
<table width=100% id='tbprev'>
<tr><td>
<form name=colchanger>
<table class=tab cellpadding=0 cellspacing=0>
<script language=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>
</form>
</td></tr>
</table>


Get free version without ©copyright link for just 5



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
- This javascript (misspelled as java script)/HTML code is given under GPL License
- i.e. Free use for those who use it as it is.
- Free, if your modification does not remove our copyright information and links.
- Detailed License information can be found here
- You can purchase the script if your requirements does not meet GPL License terms.


privacy policy     license     sitemap
© 2004-2005 HIOX INDIA - hioxindia.com

Others