5 Funkciós Kalkulátor
XHTML - fájl program, megírása:
<FORM name="formx" class="formix">
<script language="JavaScript" type="text/javascript" src="java-fájl-neve.js"></script>
<div id="calculator001">
<input type=text size=9 value=12 name="a">
<input type="button" value=" + " onClick="a_plus_b(this.form)">
<input type="button" value=" - " onClick="a_minus_b(this.form)">
<input type="button" value=" x " onClick="a_times_b(this.form)">
<input type="button" value=" / " onClick="a_div_b(this.form)">
<input type="button" value=" ^ " onClick="a_pow_b(this.form)">
<input type="number" size=9 value=3 name="b">
=
<input type "number" value=0 name="ans" size=28>
</div>
</FORM>
Css - fájl program, megírása:
.formix {padding-top:3px; padding-bottom:3px; border: 1px solid #6633ff;}
#calculator001 { margin-left:20px;}
Java (js) program, megírása:
function a_plus_b(form)
{ a=eval(form.a.value)
b=eval(form.b.value)
c=a+b
form.ans.value = c
}
function a_minus_b(form)
{ a=eval(form.a.value)
b=eval(form.b.value)
c=a-b
form.ans.value=c
}
function a_times_b(form)
{ a=eval(form.a.value)
b=eval(form.b.value)
c=a*b
form.ans.value=c
}
function a_div_b(form)
{ a=eval(form.a.value)
b=eval(form.b.value)
c=a/b
form.ans.value = c
}
function a_pow_b(form)
{ a=eval(form.a.value)
b=eval(form.b.value)
c=Math.pow(a, b)
form.ans.value = c
}