JavaScript Collector

Change color by calculating

This JavaScript requests two numbers from you to change background color by calculating one of the basic operations.... detail


How to setup

Step 1: Copy & Paste JavaScript code below in your HEAD section
JavaScript
Code:
<script language="javascript">
/*
     This script downloaded from www.JavaScriptBank.com
     Come to view and download over 2000+ free javascript at www.JavaScriptBank.com
*/

document.bgColor="violet"
function add()
{
var a,b,sum;



a=eval(document.form1.t1.value);

b=eval(document.form1.t2.value);
sum=a+b;
document.form1.t3.value=sum;
document.form1.t4.value="";
document.form1.t5.value="";
document.form1.t6.value="";
document.bgColor="red"
}

function mult()
{
var k,h,mult;
k=eval(document.form1.t1.value);
h=eval(document.form1.t2.value);
mult=k*h;
document.form1.t4.value=mult;
document.form1.t3.value="";
document.form1.t5.value="";
document.form1.t6.value="";
document.bgColor="green"
}
function sub()
{
var k,h,sub;
k=eval( document.form1.t1.value);
h=eval(document.form1.t2.value);
sub=k-h;
document.form1.t5.value=sub;
document.form1.t4.value="";
document.form1.t3.value="";
document.form1.t6.value="";
document.bgColor="blue"
}
function div()
{
var k,h,div;
document.bgcolor="#ffff00";
k=eval( document.form1.t1.value);
h=eval(document.form1.t2.value);
div=k/h;
document.form1.t6.value=div;
document.form1.t5.value="";
document.form1.t4.value="";
document.form1.t3.value="";
document.bgColor="yellow"
}
function c()
{
document.bgColor="violet"
}
</script>
	<!--
    	This script downloaded from www.JavaScriptBank.com
    	Come to view and download over 2000+ free javascript at www.JavaScriptBank.com
	-->
Step 2: Place HTML below in your BODY section
HTML
Code:
<form name="form1" style="text-align: left;">
<font color="#008000" size="5">Just enter two mumbers... and click the 
appropriate buttons for&nbsp; results</font>
<p>
Enter the first number:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 

<input type="text" name="t1" size="20"><br>
Enter the second number:  
<input type="text" name="t2" size="20">
<br>
<input type="button" name="b1" value="   ADD  " onclick="add()">
<input type="text" name="t3" size="20">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" name="b2" value="MULTIPLY " onclick="mult()">
<input type="text" name="t4" size="20"><br>
<input type="button" name="b3" value=" SUBTRACT " onclick="sub()">
<input type="text" name="t5" size="20">
<input type="button" name="b4" value=" DIVISION " onclick="div()">
<input type="text" name="t6" size="20"><br>

<input type="reset" name="res" value="CLEAR" onClick="c()">

</form>
	<!--
    	This script downloaded from www.JavaScriptBank.com
    	Come to view and download over 2000+ free javascript at www.JavaScriptBank.com
	-->


Some related scripts
- Change Color onMouseover
- Change color onMouseover
You can browse some JavaScript codes about Background




DHTML,JavaScript Tutorials - Free JavaScript eBooks - DHTMl, CSS, JavaScript eBooks Download
Quote Originally Posted by Copyright
The Site may provide, or third parties may provide, links to non-JavaScriptBank.com Internet World Wide Web sites or resources. Because JavaScriptBank.com has no control over such sites and resources, you acknowledge and agree that JavaScriptBank.com is not responsible for the availability of such external sites or resources, and does not endorse and is not responsible or liable for any content, advertising, products, or other materials on or available from such sites or resources. You further acknowledge and agree that JavaScriptBank.com shall not be responsible or liable, directly or indirectly, for any damage or loss caused or alleged to be caused by or in connection with use of or reliance on any such content, goods or services available on or through any such site or resource.