Kalkulačka (2) -
zdrojový kód
<html>
<head>
<title>Java Script ze stránky - www.jaknaweb.com</title>
<meta name="Author" content="Pavel Doško">
<style type="text/css">
td{height:50}
h2{margin-left:45%}
td{width:12%}
a:link{color:black}
a:visited{color:black}
a:active{color:black}
a:hover{background-color:rgb(190,190,190)}
th{font-size:110%;color:black}
tr{height:40px}
</style>
<script language="Javascript">
var retezec=0;
var retezecdva=0;
function PrictiKRetezci1()
{
vypis=1;
if(document.all.text3.value=='^'||document.all.text3.value=='+'||document.all.text3.value=='-'||document.all.text3.value=='/'||document.all.text3.value=='*')
{
document.all.text2.value+=vypis;
document.all.text6.value+=vypis;
}
else
{
document.all.text1.value+=vypis;
document.all.text6.value+=vypis;
}
}
function PrictiKRetezci2()
{
vypis=2;
if(document.all.text3.value=='^'||document.all.text3.value=='+'||document.all.text3.value=='-'||document.all.text3.value=='/'||document.all.text3.value=='*')
{
document.all.text2.value+=vypis;
document.all.text6.value+=vypis;
}
else
{
document.all.text1.value+=vypis;
document.all.text6.value+=vypis;
}
}
function PrictiKRetezci3()
{
vypis=3;
if(document.all.text3.value=='^'||document.all.text3.value=='+'||document.all.text3.value=='-'||document.all.text3.value=='/'||document.all.text3.value=='*')
{
document.all.text2.value+=vypis;
document.all.text6.value+=vypis;
}
else
{
document.all.text1.value+=vypis;
document.all.text6.value+=vypis;
}
}
function PrictiKRetezci4()
{
vypis=4;
if(document.all.text3.value=='^'||document.all.text3.value=='+'||document.all.text3.value=='-'||document.all.text3.value=='/'||document.all.text3.value=='*')
{
document.all.text2.value+=vypis;
document.all.text6.value+=vypis;
}
else
{
document.all.text1.value+=vypis;
document.all.text6.value+=vypis;
}
}
function PrictiKRetezci5()
{
vypis=5;
if(document.all.text3.value=='^'||document.all.text3.value=='+'||document.all.text3.value=='-'||document.all.text3.value=='/'||document.all.text3.value=='*')
{
document.all.text2.value+=vypis;
document.all.text6.value+=vypis;
}
else
{
document.all.text1.value+=vypis;
document.all.text6.value+=vypis;
}
}
function PrictiKRetezci6()
{
vypis=6;
if(document.all.text3.value=='^'||document.all.text3.value=='+'||document.all.text3.value=='-'||document.all.text3.value=='/'||document.all.text3.value=='*')
{
document.all.text2.value+=vypis;
document.all.text6.value+=vypis;
}
else
{
document.all.text1.value+=vypis;
document.all.text6.value+=vypis;
}
}
function PrictiKRetezci7()
{
vypis=7;
if(document.all.text3.value=='^'||document.all.text3.value=='+'||document.all.text3.value=='-'||document.all.text3.value=='/'||document.all.text3.value=='*')
{
document.all.text2.value+=vypis;
document.all.text6.value+=vypis;
}
else
{
document.all.text1.value+=vypis;
document.all.text6.value+=vypis;
}
}
function PrictiKRetezci8()
{
vypis=8;
if(document.all.text3.value=='^'||document.all.text3.value=='+'||document.all.text3.value=='-'||document.all.text3.value=='/'||document.all.text3.value=='*')
{
document.all.text2.value+=vypis;
document.all.text6.value+=vypis;
}
else // by Pavel
{
document.all.text1.value+=vypis;
document.all.text6.value+=vypis;
}
}
function PrictiKRetezci9()
{
vypis=9;
if(document.all.text3.value=='^'||document.all.text3.value=='+'||document.all.text3.value=='-'||document.all.text3.value=='/'||document.all.text3.value=='*')
{
document.all.text2.value+=vypis;
document.all.text6.value+=vypis;
}
else
{
document.all.text1.value+=vypis;
document.all.text6.value+=vypis;
}
}
function PrictiKRetezci0()
{
vypis=0;
if(document.all.text3.value=='^'||document.all.text3.value=='+'||document.all.text3.value=='-'||document.all.text3.value=='/'||document.all.text3.value=='*')
{
document.all.text2.value+=vypis;
document.all.text6.value+=vypis;
}
else
{
document.all.text1.value+=vypis;
document.all.text6.value+=vypis;
}
}
function PrictiKRetezciTecku()
{
vypis='.';
if(document.all.text3.value=='^'||document.all.text3.value=='+'||document.all.text3.value=='-'||document.all.text3.value=='/'||document.all.text3.value=='*')
{
document.all.text2.value+=vypis;
document.all.text6.value+=vypis;
}
else
{
document.all.text1.value+=vypis;
document.all.text6.value+=vypis;
}
}
function XLomenoJedna()
{
var xyz=document.all.text1.value;
var vys=1/xyz;
document.all.text4.value=vys;
}
function Pi()
{
document.all.text2.value=Math.PI;
document.all.text6.value+=Math.PI;
}
function AbsolutniHodnota()
{
document.all.text4.value=Math.abs(document.all.text1.value);
}
function Sinus()
{
var sin=document.all.text1.value;
rad=(Math.PI/180)*sin;
sinus=Math.sin(rad);
document.all.text4.value=sinus;
}
function Cosinus()
{
var cosin=document.all.text1.value;
rad=(Math.PI/180)*cosin;
cosinus=Math.cos(rad);
document.all.text4.value=cosinus;
}
function Tangens()
{
var tan=document.all.text1.value;
rad=(Math.PI/180)*tan;
tangens=Math.tan(rad);
document.all.text4.value=tangens;
}
function PrictiKRetezciDeleno()
{
vypis='/';
document.all.text3.value=vypis;
document.all.text6.value+=document.all.text3.value;
}
function PrictiKRetezciNasobeno()
{
vypis='*';
document.all.text3.value=vypis;
document.all.text6.value+=document.all.text3.value;
}
function PrictiKRetezciMinus()
{
vypis='-';
document.all.text3.value=vypis;
document.all.text6.value+=document.all.text3.value;
}
function PrictiKRetezciPlus()
{
vypis='+';
document.all.text3.value=vypis;
document.all.text6.value+=document.all.text3.value;
}
function Faktorial()
{
var f=document.all.text1.value;
var min=0;
var c=1;
if(f>170)
{
document.all.text4.value="tak moc, že to PC nezvládá";
}
else
{
while(f>min&&f<=170)
{
c=c*f;
f--;
}
if(f==0)
{
document.all.text4.value=c;
}
}
}
function C()
{
document.all.text1.value="";
document.all.text2.value="";
document.all.text3.value="";
document.all.text4.value="";
document.all.text6.value="";
}
function ZmenZnamenko()
{
var zmeneno;
zmeneno=(document.all.text1.value*(-1));
document.all.text1.value=zmeneno;
document.all.text6.value=zmeneno;
}
function NaXtou()
{
document.all.text3.value='^';
document.all.text6.value+=document.all.text3.value;
}
function M()
{
document.all.text5.value=document.all.text1.value;
}
function MR()
{
document.all.text2.value=document.all.text5.value;
document.all.text6.value+=document.all.text5.value;
}
function XM()
{
document.all.text5.value=0;
}
function Vysledek()
{
var vysledek;
var prvni=document.all.text1.value;
var znamenko=document.all.text3.value;
var druhy=document.all.text2.value;
if(znamenko=='+')
{
vysledek=(eval(self.document.forms.f.text1.value)+eval(self.document.forms.f.text2.value));
}
else if(znamenko=='-')
{
vysledek=prvni-druhy;
}
else if(znamenko=='/')
{
vysledek=prvni/druhy;
}
else if(znamenko=='*')
{
vysledek=prvni*druhy;
}
else if(znamenko=='^')
{
var cislo=document.all.text1.value;
var na=document.all.text2.value;
var v=1;
var vysl;
while(na>0)
{
v=v*cislo;
na--;
}
if(cislo==0)
{
vysledek=0;
}
if(na==0&&cislo>0)
{
vysledek=v;
}
}
document.all.text4.value=vysledek;
document.all.text1.value="";
document.all.text2.value="";
document.all.text3.value="";
}
function VysledekDo1()
{
document.all.text1.value=document.all.text4.value;
document.all.text6.value=document.all.text4.value;
}
</script>
</head>
<body>
<h2>Kalkulačka</h2>
<table border=1 align=center width=60% cellspacing=10>
<tr align=right>
<td colspan=8>
<form name="f">
<input type="text" id="text6" style="text-align:center" size=100% readonly>
<input type="hidden" id="text1" style="text-align:center" size=30 readonly>
<input type="hidden" id="text3" style="text-align:center" size=1 readonly>
<input type="hidden" id="text2" style="text-align:center" size=30 readonly><br>
<b>Výsledek :</b> <input type="text" onclick="VysledekDo1();" id="text4" style="text-align:center;font-weight:bold;" size=30 readonly></td>
<tr align=center>
<td><button type="button" id="c" onclick="C();"><table border=0 height=30 width=30><tr><th> CE </th></tr></table></button>
</td>
<td>
<button type="button" id="sinus" onclick="Sinus();"><table border=0 height=30 width=30><tr><th>sin</th></tr></table></button>
</td>
<td>
<button type="button" id="nadruhou" onclick="NaXtou();"><table border=0 height=30 width=30><tr><th>x^y</th></tr></table></button>
</td>
<td>
<button type="button" id="7" onclick="PrictiKRetezci7();"><table border=0 height=30 width=30><tr><th> 7 </th></tr></table></button>
</td>
<td>
<button type="button" id="8" onclick="PrictiKRetezci8();"><table border=0 height=30 width=30><tr><th> 8 </th></tr></table></button>
</td>
<td>
<button type="button" id="9" onclick="PrictiKRetezci9();"><table border=0 height=30 width=30><tr><th> 9 </th></tr></table></button>
</td>
<td>
<button type="button" id="deleno" onclick="PrictiKRetezciDeleno();"><table border=0 height=30 width=30><tr><th> / </th></tr></table></button>
</td>
<td>
<button type="button" id="xm" onclick="XM();"><table border=0 height=30 width=30><tr><th>MC</th></tr></table></button>
</td>
</tr>
<tr align=center>
<td>
 
</td>
<td>
<button type="button" id="cosinus" onclick="Cosinus();"><table border=0 height=30 width=30><tr><th>cos</th></tr></table></button>
</td>
<td>
<button type="button" id="x1" onclick="XLomenoJedna();"><table border=0 height=30 width=30><tr><th>1/x</th></tr></table></button>
</td>
<td>
<button type="button" id="4" onclick="PrictiKRetezci4();"><table border=0 height=30 width=30><tr><th> 4 </th></tr></table></button>
</td>
<td>
<button type="button" id="5" onclick="PrictiKRetezci5();"><table border=0 height=30 width=30><tr><th> 5 </th></tr></table></button>
</td>
<td>
<button type="button" id="6" onclick="PrictiKRetezci6();"><table border=0 height=30 width=30><tr><th> 6 </th></tr></table></button>
</td>
<td>
<button type="button" id="nasobeno" onclick="PrictiKRetezciNasobeno();"><table border=0 height=30 width=30><tr><th> * </th></tr></table></button>
</td>
<td>
<button type="button" id="mr" onclick="MR();"><table border=0 height=30 width=30><tr><th>MR</th></tr></table></button>
</td>
</tr>
<tr align=center>
<td>
 
</td>
<td>
<button type="button" id="tan" onclick="Tangens();"><table border=0 height=30 width=30><tr><th>tan</th></tr></table></button>
</td>
<td>
<button type="button" id="pi" onclick="Pi();"><table border=0 height=30 width=30><tr><th> PI </th></tr></table></button>
</td>
<td>
<button type="button" id="1" onclick="PrictiKRetezci1();"><table border=0 height=30 width=30><tr><th> 1 </th></tr></table></button>
</td>
<td>
<button type="button" id="2" onclick="PrictiKRetezci2();"><table border=0 height=30 width=30><tr><th> 2 </th></tr></table></button>
</td>
<td>
<button type="button" id="3" onclick="PrictiKRetezci3();"><table border=0 height=30 width=30><tr><th> 3 </th></tr></table></button>
</td>
<td>
<button type="button" id="minus" onclick="PrictiKRetezciMinus();"><table border=0 height=30 width=30><tr><th> - </th></tr></table></button>
</td>
<td>
<button type="button" id="m" onclick="M();"><table border=0 height=30 width=30><tr><th> M+ </th></tr></table></button>
</td>
</tr>
<tr align=center>
<td>
 
</td>
<td>
<button type="button" id="abs" onclick="AbsolutniHodnota();"><table border=0 height=30 width=30><tr><th>abs</th></tr></table></button>
</td>
<td>
<button type="button" id="fakt" onclick="Faktorial();"><table border=0 height=30 width=30><tr><th> n! </th></tr></table></button>
</td>
<td>
<button type="button" id="0" onclick="PrictiKRetezci0();"><table border=0 height=30 width=30><tr><th> 0 </th></tr></table></button>
</td>
<td>
<button type="button" id="." onclick="PrictiKRetezciTecku();"><table border=0 height=30 width=30><tr><th> . </th></tr></table></button>
</td>
<td>
<button type="button" id="zmen" onclick="ZmenZnamenko();"><table border=0 height=30 width=30><tr><th>+/-</th></tr></table></button>
</td>
<td>
<button type="button" id="plus" onclick="PrictiKRetezciPlus();"><table border=0 height=30 width=30><tr><th> + </th></tr></table></button>
</td>
<td>
<button type="button" id="rovnase" onclick="Vysledek();"><table border=0 height=30 width=30><tr><th> = </th></tr></table></button>
</td>
</tr>
</table>
</body>
</html>