Wednesday, December 28, 2011

Grid Accordion in jQuery

The Grid Accordion is an advanced accordion navigation that offer an interesting method to display your portfolio and by combining the functionality of a thumbnail grid and an accordion panel

  You have the option to use either XML or HTML .Accordions are a UI pattern where you click on a title 
(in a vertical stack of titles) and a panel of content reveals itself below.


Features

  • supports XML and HTML
  • easy to customize
  • multiple Grid Accordions on the same page
  • supports captions with simple text or HTML text
  • you can add a link to each panel
  • auto slideshow mode
  • shuffled panels
  • public methods which allow you to control the accordion using outside input (e.g. openPanel(3), nextPanel(), previousPanel(), getPanelAt(2) etc.)
  • callback functions

Navigator Detect: Like Code Name, Browser Name, Browser Version, Cookies Enabled,Platform

Navigator Detect: Like Code Name, Browser Name, Browser Version, Cookies Enabled,Platform

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Browser Detect</title>
</head>

<body>
<center>
<div id="example"></div>

<script type="text/javascript">

txt = "<p>Browser CodeName: " + navigator.appCodeName + "</p>";
txt+= "<p>Browser Name: " + navigator.appName + "</p>";
txt+= "<p>Browser Version: " + navigator.appVersion + "</p>";
txt+= "<p>Cookies Enabled: " + navigator.cookieEnabled + "</p>";
txt+= "<p>Platform: " + navigator.platform + "</p>";
txt+= "<p>User-agent header: " + navigator.userAgent + "</p>";

document.getElementById("example").innerHTML=txt;

</script>
</center>
</body>
</html>

calculator : For Addition(+), Subtraction(-), Multiplication(*), Division(/)

calculator : For Addition(+), Subtraction(-), Multiplication(*), Division(/)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>calculator</title>
<script language="javascript">
function add()
{
var value1=document.calculate.inputA.value
var value2=document.calculate.inputB.value
document.calculate.output.value=value1+value2
}

function sub()
{
var value1=document.calculate.inputA.value
var value2=document.calculate.inputB.value
document.calculate.output.value=value1-value2
}

function multiply()
{
var value1=document.calculate.inputA.value
var value2=document.calculate.inputB.value
document.calculate.output.value=value1*value2
}

function division()
{
var value1=document.calculate.inputA.value
var value2=document.calculate.inputB.value
document.calculate.output.value=value1/value2
}

</script>
</head>

<body>
<center>
<h3> Calculator</h3>
<form name="calculate">
 Enter the first value <input type="text" name="inputA" value="" size="8" />
Enter the second value <input type="text" name="inputB" value="" size="8" /><br />
<br /><br />
<input type="button" value="+" onclick="add()" />
<input type="button" value="-" onclick="sub()" />
<input type="button" value="*" onclick="multiply()" />
<input type="button" value="/" onclick="division()"  />
<p> </p>
Result is  <input type="text" name="output" size="8" />
</form>
</body>
</html>

Click a button show a massage through an alert box

Example: When you click the button the message will display through an alert box.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>button</title>
<script language="javascript">
function showMsg(msg) {
alert("The button sent:" + msg)
}

</SCRIPT>
</head>

<body>
<center>
<h3>When you click the button the message will display through an alert box</h3>
<form>
<input type="button" value="click me" onclick="showMsg('The button has been clicked.')" />
</form>
</center>
</body>
</html>

Sunday, December 25, 2011

Use of first(), last(), eq() function


Example : change the background and foreground effect of the paragraph when you click on the button by using css [first(), last(), eq()] function.

<html>
<head>
<title> css function</title>
<script type="text/javascript" src="../jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("p").css("color", "#333");
$("p:first").css("background", "yellow");
$("p:last").css("background", "green");
$("p:eq(3)").css("font", "20px tahoma");
$("p").eq(2).css("font-style","italic");
});
});
</script>
</head>

<body>
<center>
<h2>change the background and foreground effect of the paragraph when you click on the button by using css[first(), last(), eq()] function.</h2>
<p>[I am the first paragraph. when you click on the button, it will be change the effect of background and foreground.] </p>
<p>[I am the second paragraph. when you click on the button, it will be change the effect of background and foreground.] </p>
<p>[I am the third paragraph. when you click on the button, it will be change the effect of background and foreground.] </p>
<p>[I am the fourth paragraph. when you click on the button, it will be change the effect of background and foreground.] </p>
<p>[I am fifth paragraph. when you click on the button, it will be change the effect of background and foreground.] </p>
<button>Click me</button>
</center>
</body>
</html>

change the background and foreground effect


Example : change the background and foreground effect of the paragraph when you click on the button.

<html>
<head>
<title> css function</title>
<script type="text/javascript" src="../jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("p").css("color", "#fff");
$("p").css("background", "maroon");
$("p").css("font", "20px tahoma");
});
});
</script>
</head>

<body>
<center>
<h2>change the background and foreground effect of the paragraph when you click on the button.</h2>
<p>[I am a paragraph. when you click on the button, it will be change the effect of background and foreground.] </p>
<button>Click me</button>
</center>
</body>
</html>

change the text color of the paragraph when you click on the button


Example : change the text color of the paragraph when you click on the button

<html>
<head>
<title> css function</title>
<script type="text/javascript" src="../jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("p").css("color", "red");
});
});
</script>
</head>

<body>
<center>
<h2>change the text color of the paragraph when you click on the button.</h2>
<p>[I am a paragraph. when you click on the button, my text color will be change.] </p>
<button>Click me</button>
</center>
</body>
</html>

Hide an element when you click on the button


Example 10: Hide the paragraph when you click on the button

<html>
<head>
<title> Hide function</title>
<script type="text/javascript" src="../jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("p").hide();
});
});
</script>
</head>

<body>
<center>
<h2>Hide the paragraph when you click on the button.</h2>
<p>[I am a paragraph. when you click on the button, I will hide.] </p>
<button>Click me</button>
</center>
</body>
</html>

Hide an element when you click on it


Example :  Hide a paragraph when you click on it

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> hide function  </title>
<script type="text/javascript" src="../jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("p").click(function(){
$(this).hide();
});
});
</script>

</head>

<body style="width:800px; margin:0 auto">
<center>
<h3> Hide a paragraph when you click on it.</h3>
<p> Click upon me, I will hide.</p>
</center>


</body>
</html>

Randomly selected Background effect


Example:  Randomly selected Background effect 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> Random Background effect  </title>

<script language="javascript">
function backcolor(form) {
demo = ""
for (var i = 0; i < 16; i++) {
demo = form.color[i].value
if (form.color[i].checked){ document.bgColor = demo }
   }
}
function randombackground() {
document.bgColor = getColor()
}
function getColor(){
currentdate = new Date()
backgroundcolor = currentdate.getSeconds()
if (backgroundcolor > 44)
backgroundcolor = backgroundcolor - 45
else if (backgroundcolor > 29)
backgroundcolor = backgroundcolor - 30
else if (backgroundcolor > 15)
backgroundcolor = backgroundcolor - 16
if (backgroundcolor == 0 )
return "olive";
else if (backgroundcolor == 1 )
return "teal";
else if (backgroundcolor == 2 )
return "red";
else if (backgroundcolor == 3 )
return "blue";
else if (backgroundcolor == 4 )
return "maroon";
else if (backgroundcolor == 5 )
return "navy";
else if (backgroundcolor == 6 )
return "lime";
else if (backgroundcolor == 7 )
return "fuschia";
else if (backgroundcolor == 8 )
return "green";
else if (backgroundcolor == 9 )
return "purple";
else if (backgroundcolor == 10 )
return "gray";
else if (backgroundcolor == 11 )
return "yellow";
else if (backgroundcolor == 12 )
return "aqua";
else if (backgroundcolor == 13 )
return "black";
else if (backgroundcolor == 14 )
return "white";
else if (backgroundcolor == 15 )
return "silver";
}
</script>

</head>

<body style="width:800px; margin:0 auto">
<center>
<h3>random background effect</h3>
<form>
<input type="button" value=" random background effect" onclick="randombackground()">
</form>
</center>


</body>
</html>

Select the value from the list by using option button for background effect.


Example 9:   Select the value from the list by using option button for         background effect.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> Background effect  </title>

</head>

<body style="width:800px; margin:0 auto">
<center>
<h3>Select the value from the list by using option button for  background effect.  </h3>

<div style="font-size:20px">
<select size=10 name=clr onchange="document.bgcolor=this.options[this.selectedindex].value">
<option value="olive green">olive green
<option value="cream">cream
<option value="ocean">ocean
<option value="aqua">aqua
<option value="skyblue">skyblue
<option value="white" selected>white
<option value="blue">blue
<option value="aquamarine">aquamarine
<option value="chocolate">chocolate
<option value="darkred">dark red
<option value="gold">gold
<option value="red">red
<option value="yellow">yellow
<option value="hotpink">hotpink
<option value="lime">lime
<option value="darkkhaki">dark khaki
<option value="cadetblue ">cadet blue
<option value="darkgoldenrod">dark goldenrod
<option value="darkslateblue">dark slate
<option value="grass">grass green
<option value="deeppink">deep pink
<option value="darksalmon">dark salmon
<option value="salmon">salmon
<option value="tan">tan
<option value="wheat">wheat
<option value="tomato">tomato
<option value="springgreen">springgreen
<option value="turquoise">turquoise
<option value="white" selected>white

</select>
</form></div>
</center>
</body>
</html>

onmouseover each character changes the background effect.


Example :  onmouseover each character changes the background effect.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> Background effect  </title>

</head>

<body style="width:800px; margin:0 auto">
<center>
<h3> Onmouseover each character  change the background effect </h3>

<div style="font-size:20px">

<a href="" onmouseover ="document.bgcolor='maroon'">m</a>
<a href="" onmouseover ="document.bgcolor='orange'">o</a>
<a href="" onmouseover ="document.bgcolor='violate'">v</a>
<a href="" onmouseover ="document.bgcolor='green'">e</a>
<a href="" onmouseover ="document.bgcolor='cyan'">c</a>
<a href="" onmouseover ="document.bgcolor='gray'">u</a>
<a href="" onmouseover ="document.bgcolor='red'">r</a>
<a href="" onmouseover ="document.bgcolor='silver'">s</a>
<a href="" onmouseover ="document.bgcolor='ocean'">o</a>
<a href="" onmouseover ="document.bgcolor='purple'">r</a>
<a href="" onmouseover ="document.bgcolor='aqua'">a</a>
<a href="" onmouseover ="document.bgcolor='silver'">c</a>
<a href="" onmouseover ="document.bgcolor='lightslategray'">c</a>
<a href="" onmouseover ="document.bgcolor='azure'">o</a>
<a href="" onmouseover ="document.bgcolor='lightgreen'">r</a>
<a href="" onmouseover ="document.bgcolor='lightblue'">d</a>
<a href="" onmouseover ="document.bgcolor='white'">i</a>
<a href="" onmouseover ="document.bgcolor='magenta'">n</a>
<a href="" onmouseover ="document.bgcolor='gold'">g</a>
<a href="" onmouseover ="document.bgcolor='brown'">t</a>
<a href="" onmouseover ="document.bgcolor='skyblue'">h</a>
<a href="" onmouseover ="document.bgcolor='black'">e</a>
<a href="" onmouseover ="document.bgcolor='pink'">e</a>
<a href="" onmouseover ="document.bgcolor='olive green'">a</a>
<a href="" onmouseover ="document.bgcolor='dark teal'">c</a>
<a href="" onmouseover ="document.bgcolor='tan'">h</a>
<a href="" onmouseover ="document.bgcolor='dark yellow'">a</a>
<a href="" onmouseover ="document.bgcolor='white'">r</a>
<a href="" onmouseover ="document.bgcolor='bright green'">a</a>
<a href="" onmouseover ="document.bgcolor='azure'">c</a>
<a href="" onmouseover ="document.bgcolor='lightgreen'">t</a>
<a href="" onmouseover ="document.bgcolor='lightblue'">e</a>
<a href="" onmouseover ="document.bgcolor='white'">r</a>
<a href="" onmouseover ="document.bgcolor='silver'">g</a>
<a href="" onmouseover ="document.bgcolor=' lime'">e</a>
<a href="" onmouseover ="document.bgcolor=' deeppink'">t</a>
<a href="" onmouseover ="document.bgcolor=' salmon’ ">r</a>
<a href="" onmouseover ="document.bgcolor=tan’">e</a>
<a href="" onmouseover ="document.bgcolor=wheat’">s</a>
<a href="" onmouseover ="document.bgcolor=tomato’">u</a>
<a href="" onmouseover ="document.bgcolor=’ springgreen’">l</a>
<a href="" onmouseover ="document.bgcolor=turquoise’">t</a>

</div>
</center>
</body>
</html>

Onmouseover change the background effect


Example :  onmouseover change the background effect

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> Background effect  </title>

</head>

<body style="width:800px; margin:0 auto">
<center>
<h3> Onmouseover change the background effect </h3>


[<a href="/"
onmouseover="document.bgColor='green'">Green</a>]
[<a href="/"
onmouseover="document.bgColor='greem'">Bright Green</a>]
[<a href="/"
onmouseover="document.bgColor='seagreen'">Sea Green</a>]
[<a href="/"
onmouseover="document.bgColor='red'">Red</a>]<BR>
[<a href="/"
onmouseover="document.bgColor='magenta'">Magenta</a>]
[<a href="/"
onmouseover="document.bgColor='fusia'">Fusia</a>]
[<a href="/"
onmouseover="document.bgColor='pink'">Pink</a>]
[<a href="/"
onmouseover="document.bgColor='purple'">Purple</a>]<BR>
[<a href="/"
onmouseover="document.bgColor='navy'">Navy</a>]
[<a href="/"
onmouseover="document.bgColor='blue'">Blue</a>]
[<a href="/"
onmouseover="document.bgColor='royalblue'">Royal Blue</a>]
[<a href="/"
onmouseover="document.bgColor='Skyblue'">Sky Blue</a>]<BR>
[<a href="/"
onmouseover="document.bgColor='yellow'">Yellow</a>]
[<a href="/"
onmouseover="document.bgColor='brown'">Brown</a>]
[<a href="/"
onmouseover="document.bgColor='almond'">Almond</a>]
[<a href="/"
onmouseover="document.bgColor='white'">White</a>]<BR>
[<a href="/"
onmouseover="document.bgColor='black'">Black</a>]
[<a href="/"
onmouseover="document.bgColor='coral'">Coral</a>]
[<a href="/"
onmouseover="document.bgColor='olivedrab'">Olive Drab</a>]
[<a href="/"
onmouseover="document.bgColor='orange'">Orange</a>]
[<a href="/"
onmouseover="document.bgColor='maroon'">maroon</a>]
[<a href="/"
onmouseover="document.bgColor='gray'">gray</a>]
[<a href="/"
onmouseover="document.bgColor='silver'">silver</a>]
[<a href="/"
onmouseover="document.bgColor='gold'">gold</a>]

</center>
</body>
</html>

continuously change the background color by using loop


Example :  continuously change the background color by using loop

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> Background effect by using loop </title>


<script language="javascript">

var COLOR = 999999
var woot = 0
function stoploop() {
document.bgColor = '#fff';
clearTimeout(loopID);
}
function loopBackground() {
if (COLOR > 0) {
document.bgColor = '#' + COLOR
COLOR -= 111111
loopID = setTimeout("loopBackground()",1)
} else {
document.bgColor = '#000000'
woot += 10
COLOR = 999999
COLOR -= woot
loopID = setTimeout("loopBackground()",1)
   }
}
</script>
</head>

<body style="width:800px; margin:0 auto">
<center>
<h3> continuously change the background color by using loop </h3>


<FORM NAME="background">
<INPUT TYPE="button" VALUE="Start bgColor WARP"
onClick="loopBackground()">
<br>
<input type="button" value="Stop bgColor WARP" onClick="stoploop()">
</FORM>


</center>
</body>
</html>

Background effect by using Red-Green-Blue buttons


Example :  choose the color you want by its name, or create a unique color by using the "+" and "-" with the Red-Green-Blue buttons.

<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> Background effect </title>


<script language="javascript">

function changeBackground(hexNumber) {
document.bgColor=hexNumber
}
prefix="#"
rnum1=0
bnum1=0
gnum1=0
rnum2=0
bnum2=0
gnum2=0
hexNumber2="#000000";
rcount=0;
bcount=0;
gcount=0;
function num2hex(num) {
if (num==15) return "f";
else if (num==14) return "e";
else if (num==13) return "d";
else if (num==12) return "c";
else if (num==11) return "b";
else if (num==10) return "a";
else if (num==9) return "9";
else if (num==8) return "8";
else if (num==7) return "7";
else if (num==6) return "6";
else if (num==5) return "5";
else if (num==4) return "4";
else if (num==3) return "3";
else if (num==2) return "2";
else if (num==1) return "1";
else return "0";
}
function changeBackground2(number) {
if(number == 1) {
rnum1=rcount%16;
if (rcount <15) {
rcount=rcount+1;
  }
}
if(number == 2) {
gnum1=gcount%16;
if (gcount <15) {
gcount=gcount+1;
  }
}
if(number == 3) {
bnum1=bcount%16;
if (bcount <15) {
bcount=bcount+1;
  }
}
if(number == 4) {
rnum1=rcount%16;
if (rcount > 0) {
rcount=rcount-1;
  }
}
if(number == 5) {
gnum1=gcount%16;
if (gcount > 0) {
gcount=gcount-1;
  }
}
if(number == 6) {
bnum1=bcount%16;
if (bcount > 0) {
bcount=bcount-1;
  }
 }
hexNumber2 = prefix+num2hex(rnum1)+num2hex(rnum2)+num2hex(gnum1)+num2hex(gnum2)+num2hex(bnum1)+num2hex(bnum2);
  document.bgColor=hexNumber2
}
</script>
</head>

<body>
<center>
<h3> choose the color you want by its name, or create a unique color by using the "+" and "-" with the Red-Green-Blue buttons. </h3>
<Center>
<form method="post" name="background">
<table width=350 border="3" cellpadding="3">
<tr>
<td align=center><input type="button" value="red" onclick="changebackground('#ff0000')"></td>
<td align=center><input type="button" value="green" onclick="changebackground('#336600')"></td>
<td align=center><input type="button" value="blue" onclick="changebackground('#0000ff')"></td>
<td align=center><input type="button" value="white" onclick="changebackground('#ffffff')"></td>
<td align=center><input type="button" value="black" onclick="changebackground('#000000')"></td>
<td align=center><input type="button" value="grey" onclick="changebackground('#c0c0c0')"></td>
<td align=center><input type="button" value="yellow" onclick="changebackground('#ffff00')"></td>

</tr>
</table>
<table width=350 border="3" cellpadding="3">
<tr><td><center>variable background color changer</center></td>
</tr>
</table>
<table width=350 border="3" cellpadding="3">
<tr>
<td align=center><input type="button" value="+ red" onclick="changebackground2(1)"><p>
<input type="button" value="- red" onclick="changebackground2(4)"></td>
<td align=center><input type="button" value="+ green" onclick="changebackground2(2)"><p>
<input type="button" value="- green" onclick="changebackground2(5)"></td>
<td align=center><input type="button" value="+ blue" onclick="changebackground2(3)"><p>
<input type="button" value="- blue" onclick="changebackground2(6)"></td>
</tr>
</table>
<table width=350 border="3" cellpadding="3">
<tr>
<td><center>keep pressing buttons to change color<br>
(the color will start as black)</center></td>
</tr>
</table>
</form>
</center>

</body>
</html>

Background and Foreground effect by using increment and decrement value


Example :  Color Chooser in Background and Foreground by using '+' and '-' buttons for increment and decrement value

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Color Chooser in Background and Foreground</title>


<script language="javascript">

redValue = 255;
blueValue = 255;
greenValue = 255;
redForeValue = 0;
blueForeValue = 0;
greenForeValue = 0;
maxValue = 255;
hexValues = new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F");
i = 0;
function toHex(integer) {
hexDigit1 = Math.floor(integer / 16);
hexDigit2 = (integer % 16);
return hexValues[hexDigit1] + hexValues[hexDigit2];
}
function shiftFG() {
redFGHex = toHex(redForeValue);
blueFGHex = toHex(blueForeValue);
greenFGHex = toHex(greenForeValue);
bigFGHex = redFGHex + greenFGHex + blueFGHex;
document.fgColor = bigFGHex;
document.Interface.fgHex.value = bigFGHex;
document.Interface.redFG.value = redForeValue;
document.Interface.blueFG.value = blueForeValue;
document.Interface.greenFG.value = greenForeValue;
}
function shiftBG() {
redHex = toHex(redValue);
blueHex = toHex(blueValue);
greenHex = toHex(greenValue);
bigHex = redHex + greenHex + blueHex;
document.bgColor = bigHex;
document.Interface.bgHex.value = bigHex;
document.Interface.red.value = redValue;
document.Interface.blue.value = blueValue;
document.Interface.green.value = greenValue;
}
function incrementRed(isBackground) {
if (isBackground == true ) {
redValue = redValue + 8;
if (redValue > maxValue) {
redValue = 0;
}
shiftBG();
}
if (isBackground == false) {
redForeValue = redForeValue + 8;
if (redForeValue > maxValue) {
redForeValue = 0;
}
shiftFG();
   }
}
function decrementRed(isBackground) {
if (isBackground == true) {
redValue = redValue - 8;
if (redValue < 0 ) {
redValue = 255;
}
shiftBG();
}
else {
redForeValue = redForeValue - 8;
if (redForeValue < 0) {
redForeValue = 255;
}
shiftFG();
   }
}
function setRed(value, isBackground) {
if(value > -1 && value < 256) {
if( isBackground == true ) {
redValue = value;
shiftBG();
}
else {
redForeValue = value;
shiftFG();
      }
   }
}
function incrementBlue(isBackground) {
if ( isBackground == true ) {
blueValue = blueValue + 8;
if (blueValue > maxValue) {
blueValue = 0;
}                                 
shiftBG();
}
else {
blueForeValue = blueForeValue + 8;
if ( blueForeValue > maxValue ) {
blueForeValue = 0;
}
shiftFG();
   }
}
function decrementBlue(isBackground) {
if (isBackground == true) {
blueValue = blueValue - 8;
if (blueValue < 0) {
blueValue = 255;
}
shiftBG();
}
else {
blueForeValue = blueForeValue - 8;
if (blueForeValue < 0) {
blueForeValue = 255;
}
shiftFG();
   }
}
function setBlue(value, isBackground) {
if (value > -1 && value < 256) {
if ( isBackground == true ) {
blueValue = value;
shiftBG();
}
else {
blueForeValue = value;
shiftFG();
      }
   }
}
function incrementGreen(isBackground) {
if (isBackground == true) {
greenValue = greenValue + 8;
if (greenValue > maxValue) {
greenValue = 0;
}
shiftBG();
}
else {
greenForeValue = greenForeValue + 8;
if (greenForeValue > maxValue) {
greenForeValue = 0;
}
shiftFG();
   }
}
function decrementGreen(isBackground) {
if (isBackground == true) {
greenValue = greenValue - 8;
if (greenValue < 0 ) {
greenValue = 255;
}
shiftBG();
}
else {
greenForeValue = greenForeValue - 8;
if (greenForeValue < 0) {
greenForeValue = 255;
}
shiftFG();
   }
}
function setGreen(value, isBackground) {
if ( value > -1 && value < 256 ) {
if ( isBackground == true ) {
greenValue = value;
shiftBG();
}
else {
greenForeValue = value;
shiftFG();
      }
   }
}
function unHex(string, fgbg) {
hex = string.toUpperCase();
counter = 0;
while (hex.charAt(0) != hexValues[counter])
counter++;
r = 16 * counter;
counter = 0;
while (hex.charAt(1) !=  hexValues[counter])
counter++;
r = r + counter;
counter = 0;
while (hex.charAt(2) != hexValues[counter])
counter++;
g = 16 * counter;
counter = 0;
while (hex.charAt(3) != hexValues[counter])
counter++;
g = g + counter;
counter = 0;
while (hex.charAt(4) != hexValues[counter])
counter++;
b = 16 * counter;
counter = 0;
while (hex.charAt(5) != hexValues[counter])
counter++;
b = b + counter;
if (fgbg == "bg") {
redValue = r;
blueValue = b;
greenValue = g;
document.Interface.red.value = redValue;
document.Interface.blue.value = blueValue;
document.Interface.green.value = greenValue;
}
if (fgbg == "fg") {
redForeValue = r;
blueForeValue = b;
greenForeValue = g;
document.Interface.redFG.value = redForeValue;
document.Interface.blueFG.value = blueForeValue;
document.Interface.greenFG.value = greenForeValue;
   }
}         
function validChar(char) {
for (j = 0; j < hexValues.length; j++) {
if (char == hexValues[j]) {
return true;
   }
}
return false;
}
function isHex(string) {
if (string.length != 6) {
return false;
}
for (k = 0; k < 6; k++) {
if (! validChar(string.charAt(k))) {
return false;
   }
}
return true;
}
function setBGHex(value) {
if (isHex(value.toUpperCase())) {
document.bgColor = value;
unHex(value, "bg");
   }
}
function setFGHex(value) {
if (isHex(value.toUpperCase())) {
document.fgColor = value;
unHex(value, "fg");
   }
}
</script>
</head>

<body>
<center>
<h3> Color Chooser in Background and Foreground by using '+' and '-' buttons for increment and decrement value</h3>
<form name=Interface>
<table border=4 cellspacing=0 cellpadding=4>
<tr>
<td colspan=3 align=center>Background</td>
<td><input type=text name=bgHex onKeyup="setBGHex(this.value)"></td>
<td colspan=2 align=center>Foreground</td>
<td><input type=text name=fgHex onKeyup="setFGHex(this.value)"></td>
</tr>
<tr>
<td>Red</td>
<td><input type=button value=" + " onClick="incrementRed(true)"></td>
<td><input type=button value=" - " onClick="decrementRed(true)"></td>
<td><input type=text name="red" onKeyup="setRed(this.value, true)"></td>
<td><input type=button value=" + " onClick="incrementRed(false)"></td>
<td><input type=button value=" - " onClick="decrementRed(false)"></td>
<td><input type=text name=redFG onKeyup="setRed(this.value, false)"></td>
</tr>
<tr>
<td>Green</td>
<td><input type=button value=" + " onClick="incrementGreen(true)"></td>
<td><input type=button value=" - " onClick="decrementGreen(true)"></td>
<td><input type=text name="green" onKeyup="setGreen(this.value, true)"></td>
<td><input type=button value=" + " onClick="incrementGreen(false)"></td>
<td><input type=button value=" - " onClick="decrementGreen(false)"></td>
<td><input type=text name=greenFG onKeyup="setGreen(this.value, false)"></td>
</tr>
<tr>
<td>Blue</td>
<td><input type=button value=" + " onClick="incrementBlue(true)"></td>
<td><input type=button value=" - " onClick="decrementBlue(true)"></td>
<td><input type=text name="blue" onKeyup="setBlue(this.value, true)"></td>
<td><input type=button value=" + " onClick="incrementBlue(false)"></td>
<td><input type=button value=" - " onClick="decrementBlue(false)"></td>
<td><input type=text name=blueFG onKeyup="setBlue(this.value, false)"></td>
</tr>
</table>
</form>
</center>

</body>
</html>

Background adjustment by using buttons


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>backgound adjustment by using buttons</title>


<script language="javascript">
function color(frm, clr, val) {
v = eval("0x" + frm[clr].value) + val;
if (v < 0 || v > 255) v -= val;
v = v.toString(16).toUpperCase();
while (v.length < 2) v = "0" + v;
frm[clr].value = v; nc = "";
for(i = 1; i < 8; i += 3) nc += frm.elements[i].value;
document.bgColor = nc;
}
function setval(item) {
v = prompt("New value for " + item.name + " (00 - FF)", item.value);
if (v) {
v = eval("0x" + v);
if ((v & 255) == v) {
item.value=v.toString(16).toUpperCase();
while (item.value.length < 2) item.value = "0" + item.value;
color(document.f, item.name, 0);
      }
   }
}
</script>
</head>

<body>
<center>
<h3>Background adjustment by using buttons via red, green, blue color and the (‘>’and ‘<’)</h3>
<form name=f>
<table border=1>
<tr>
<td colspan=3 align=center bgcolor="red">RED</td>
<td colspan=3 align=center bgcolor="green">GREEN</td>
<td colspan=3 align=center bgcolor="blue">BLUE</td>
</tr>
<tr>
<td><input type=button name=rm value="<" onclick = "color(this.form, 'Red' , -1);"></td>
<td><input type=button name=Red value="AF" onclick = "setval(this);"></td>
<td><input type=button name=rp value=">" onclick = "color(this.form, 'Red', 1);"></td>
<td><input type=button name=gm value="<" onclick = "color(this.form, 'Green', -1);"></td>
<td><input type=button name=Green value="BF" onclick = "setval(this);"></td>
<td><input type=button name=gp value=">" onclick = "color(this.form, 'Green', 1);"></td>
<td><input type=button name=bm value="<" onclick = "color(this.form, 'Blue', -1);"></td>
<td><input type=button name=Blue value="CF" onclick = "setval(this);"></td>
<td><input type=button name=bp value=">" onclick = "color(this.form, 'Blue', 1);"></td>
</tr>
</table>
</form>
</center>


</body>
</html>

Web design Example


Example 1:  Background change of the cell

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>backgound change of the cell</title>

<style type="text/css">
.tditem {
font-size: 15px;
font-family: Verdana, Arial, Helvetica, sans-serif;
text-decoration: none;
color: #333333;
}
</style>
</head>

<body>
<center>
<h3>Backgound change of the cell</h3>
<table border=0 cellpadding=0 cellspacing=0>
<tr>
<td onmouseover="bgColor='blue'" onClick="window.location='page1.html'" style="cursor:hand" onmouseout="bgColor='#FFFFFF'" bgcolor="#FFFFFF" width="200" align="center" valign="center"><b><font color="#D5D5D5">
<a href="page1.html" class="tditem">
Item 1</a></font></b></td>

<td width="1" align="center">|</td>

<td onmouseover="bgColor='green'" onClick="window.location='page2.html'" style="cursor:hand" onmouseout="bgColor='#FFFFFF'" bgcolor="#FFFFFF" width="200" align="center" valign="center"><b><font color="#D5D5D5">
<a href="page2.html" class="tditem">
Item 2</a></font></b></td>

<td width="1" align="center">|</td>

<td onmouseover="bgColor='red'" onClick="window.location='page3.html'" style="cursor:hand" onmouseout="bgColor='#FFFFFF'" bgcolor="#FFFFFF" width="200" align="center" valign="center"><b><font color="#D5D5D5">
<a href="page3.html" class="tditem">
Item 3</a></font></b></td>

</tr>
</table>
</center>



</body>
</html>