nets
22-02-2006, 09:47 PM
I have nothing else to do at this moment in time, so I've decided to post some terrible small script which I wrote in one of my *lessons* at school today (instead of doing work). Sorry in advance as I rushed to finish this without checking it carefully, and there may be some errors.
<html>
<head>
<title>Calculator</title>
<style language="css" type="text/css">
.button_off{
width: 50px;
background-color: #eee;
}
.button_on{
width: 50px;
background-color: #ccc;
}
.button_clear{
width: 50px;
background-color: #d33;
}
.disp {
width: 200px;
margin-bottom: 5px;
background-color: #efefef;
color: #000;
}
</style>
<script language="JavaScript" type="text/JavaScript">
process = 'FALSE'; // Default
clear = 'FALSE'; // Default
function ac(c)
{
if(clear == 'TRUE'){
calc.disp.value = '';
clear = 'FALSE';
}
document.calc.add.disabled = false;
document.calc.sub.disabled = false;
document.calc.div.disabled = false;
document.calc.mul.disabled = false;
document.calc.clr.disabled = false;
document.calc.equ.disabled = false;
calc.disp.value = calc.disp.value+c;
}
function ao(o)
{
if(o == 'clr') {
calc.disp.value = '';
document.calc.add.disabled = true;
document.calc.sub.disabled = true;
document.calc.div.disabled = true;
document.calc.mul.disabled = true;
document.calc.clr.disabled = true;
document.calc.equ.disabled = true;
process = 'FALSE';
} else if(process == 'FALSE') {
mem = calc.disp.value;
opp = o;
process = 'TRUE';
clear = 'TRUE';
} else {
if(opp == 'mul') {
calc.disp.value = mem * calc.disp.value;
}else if(opp == 'div') {
calc.disp.value = mem / calc.disp.value;
}else if(opp == 'sub') {
calc.disp.value = mem - calc.disp.value;
}else if(opp == 'add') {
calc.disp.value = Number(mem) + Number(calc.disp.value);
}
if(o != 'equ') {
opp = o;
mem = calc.disp.value;
} else {
process = 'FALSE';
clear = 'TRUE';
}
}
}
</script>
</head>
<body>
<form name="calc">
<table cellpadding="0" cellspacing="0">
<tr>
<td colspan="4"><input type="text" class="disp" disabled name="disp" /></td>
</tr>
<tr>
<td><input type="button" class="button_off" onmouseover="className='button_on'" onmouseout="className='button_off'" value="7" onClick="ac('7')" /></td>
<td><input type="button" class="button_off" onmouseover="className='button_on'" onmouseout="className='button_off'" value="8" onClick="ac('8')" /></td>
<td><input type="button" class="button_off" onmouseover="className='button_on'" onmouseout="className='button_off'" value="9" onClick="ac('9')" /></td>
<td><input type="button" class="button_off" onmouseover="className='button_on'" onmouseout="className='button_off'" disabled name="mul" value="*" onClick="ao('mul')" /></td>
</tr>
<tr>
<td><input type="button" class="button_off" onmouseover="className='button_on'" onmouseout="className='button_off'" value="4" onClick="ac('4')" /></td>
<td><input type="button" class="button_off" onmouseover="className='button_on'" onmouseout="className='button_off'" value="5" onClick="ac('5')" /></td>
<td><input type="button" class="button_off" onmouseover="className='button_on'" onmouseout="className='button_off'" value="6" onClick="ac('6')" /></td>
<td><input type="button" class="button_off" onmouseover="className='button_on'" onmouseout="className='button_off'" disabled name="add" value="+" onClick="ao('add')" /></td>
</tr>
<tr>
<td><input type="button" class="button_off" onmouseover="className='button_on'" onmouseout="className='button_off'" value="1" onClick="ac('1')" /></td>
<td><input type="button" class="button_off" onmouseover="className='button_on'" onmouseout="className='button_off'" value="2" onClick="ac('2')" /></td>
<td><input type="button" class="button_off" onmouseover="className='button_on'" onmouseout="className='button_off'" value="3" onClick="ac('3')" /></td>
<td><input type="button" class="button_off" onmouseover="className='button_on'" onmouseout="className='button_off'" disabled name="div" value="/" onClick="ao('div')" /></td>
</tr>
<tr>
<td><input type="button" class="button_off" onmouseover="className='button_on'" onmouseout="className='button_off'" value="0" onClick="ac('0')" /></td>
<td><input type="button" class="button_clear" disabled name="clr" value="C" onClick="ao('clr')" /></td>
<td><input type="button" class="button_off" onmouseover="className='button_on'" onmouseout="className='button_off'" disabled name="equ" value="=" onClick="ao('equ')" /></td>
<td><input type="button" class="button_off" onmouseover="className='button_on'" onmouseout="className='button_off'" disabled name="sub" value="-" onClick="ao('sub')" /></td>
</tr>
</table>
</form>
</body>
</html>
P.s. It doesn't take too much brain-power to figure out the purpose of this script, so I'll leave that to you.
<html>
<head>
<title>Calculator</title>
<style language="css" type="text/css">
.button_off{
width: 50px;
background-color: #eee;
}
.button_on{
width: 50px;
background-color: #ccc;
}
.button_clear{
width: 50px;
background-color: #d33;
}
.disp {
width: 200px;
margin-bottom: 5px;
background-color: #efefef;
color: #000;
}
</style>
<script language="JavaScript" type="text/JavaScript">
process = 'FALSE'; // Default
clear = 'FALSE'; // Default
function ac(c)
{
if(clear == 'TRUE'){
calc.disp.value = '';
clear = 'FALSE';
}
document.calc.add.disabled = false;
document.calc.sub.disabled = false;
document.calc.div.disabled = false;
document.calc.mul.disabled = false;
document.calc.clr.disabled = false;
document.calc.equ.disabled = false;
calc.disp.value = calc.disp.value+c;
}
function ao(o)
{
if(o == 'clr') {
calc.disp.value = '';
document.calc.add.disabled = true;
document.calc.sub.disabled = true;
document.calc.div.disabled = true;
document.calc.mul.disabled = true;
document.calc.clr.disabled = true;
document.calc.equ.disabled = true;
process = 'FALSE';
} else if(process == 'FALSE') {
mem = calc.disp.value;
opp = o;
process = 'TRUE';
clear = 'TRUE';
} else {
if(opp == 'mul') {
calc.disp.value = mem * calc.disp.value;
}else if(opp == 'div') {
calc.disp.value = mem / calc.disp.value;
}else if(opp == 'sub') {
calc.disp.value = mem - calc.disp.value;
}else if(opp == 'add') {
calc.disp.value = Number(mem) + Number(calc.disp.value);
}
if(o != 'equ') {
opp = o;
mem = calc.disp.value;
} else {
process = 'FALSE';
clear = 'TRUE';
}
}
}
</script>
</head>
<body>
<form name="calc">
<table cellpadding="0" cellspacing="0">
<tr>
<td colspan="4"><input type="text" class="disp" disabled name="disp" /></td>
</tr>
<tr>
<td><input type="button" class="button_off" onmouseover="className='button_on'" onmouseout="className='button_off'" value="7" onClick="ac('7')" /></td>
<td><input type="button" class="button_off" onmouseover="className='button_on'" onmouseout="className='button_off'" value="8" onClick="ac('8')" /></td>
<td><input type="button" class="button_off" onmouseover="className='button_on'" onmouseout="className='button_off'" value="9" onClick="ac('9')" /></td>
<td><input type="button" class="button_off" onmouseover="className='button_on'" onmouseout="className='button_off'" disabled name="mul" value="*" onClick="ao('mul')" /></td>
</tr>
<tr>
<td><input type="button" class="button_off" onmouseover="className='button_on'" onmouseout="className='button_off'" value="4" onClick="ac('4')" /></td>
<td><input type="button" class="button_off" onmouseover="className='button_on'" onmouseout="className='button_off'" value="5" onClick="ac('5')" /></td>
<td><input type="button" class="button_off" onmouseover="className='button_on'" onmouseout="className='button_off'" value="6" onClick="ac('6')" /></td>
<td><input type="button" class="button_off" onmouseover="className='button_on'" onmouseout="className='button_off'" disabled name="add" value="+" onClick="ao('add')" /></td>
</tr>
<tr>
<td><input type="button" class="button_off" onmouseover="className='button_on'" onmouseout="className='button_off'" value="1" onClick="ac('1')" /></td>
<td><input type="button" class="button_off" onmouseover="className='button_on'" onmouseout="className='button_off'" value="2" onClick="ac('2')" /></td>
<td><input type="button" class="button_off" onmouseover="className='button_on'" onmouseout="className='button_off'" value="3" onClick="ac('3')" /></td>
<td><input type="button" class="button_off" onmouseover="className='button_on'" onmouseout="className='button_off'" disabled name="div" value="/" onClick="ao('div')" /></td>
</tr>
<tr>
<td><input type="button" class="button_off" onmouseover="className='button_on'" onmouseout="className='button_off'" value="0" onClick="ac('0')" /></td>
<td><input type="button" class="button_clear" disabled name="clr" value="C" onClick="ao('clr')" /></td>
<td><input type="button" class="button_off" onmouseover="className='button_on'" onmouseout="className='button_off'" disabled name="equ" value="=" onClick="ao('equ')" /></td>
<td><input type="button" class="button_off" onmouseover="className='button_on'" onmouseout="className='button_off'" disabled name="sub" value="-" onClick="ao('sub')" /></td>
</tr>
</table>
</form>
</body>
</html>
P.s. It doesn't take too much brain-power to figure out the purpose of this script, so I'll leave that to you.