1600 PMP mock questions 1400 CAPM mock questions 800 SCJP 6 mock questions 600 OCAJP 7 mock questions 590 OCPJP 7 mock questions 556 SCWCD 5 mock questions 500 OCEJWCD 6 mock questions pdfDownload (java,struts, hibernet etc)

Java Script Tutorials

Javascript - Calculator

<html>
<head>
<title>Javascript - Calculator</title>

<script language=javascript type="text/javascript">

var plus,minus,divide,times

function initialise(){
plus=document.calc.operator.options[0]
minus=document.calc.operator.options[1]
divide=document.calc.operator.options[2]
times=document.calc.operator.options[3]
}

function calculate()
{
x = parseInt(document.calc.val1.value)
y = parseInt(document.calc.val2.value)
if (plus.selected)
document.calc.answer.value=x + y
if (minus.selected)
document.calc.answer.value=x - y
if (divide.selected)
document.calc.answer.value=x / y
if (times.selected)
document.calc.answer.value=x * y
}

</script>

</head>

<body onLoad="initialise()">
<h2>Calculator</h2>

Enter 10 in field 1 then 20 in field 2 press answer. This should give result 30
<br>
Change the operation from + to each of the others ( -, /, * ) in turn and press answer.
<form name="calc" action="post">
<input type=text name=val1 size=10>

<select name=operator>
    <option value=plus>+
    <option value=minus>-
    <option value=divide>/
    <option value=times>*
</select>

<input type=text name=val2 size=10>
=
<input type=text name=answer size=10>
<input type=button value=answer onClick="calculate()">
</form>

<br><br>

<br>

</body>
</html>

Reviews and Comments


PMP, CAPM, PMI is a registered certification mark of the Project Management Institute, Inc

Copyright © www.techfaq360.com 2016


About US | Contact US | Privacy Policy | Terms and Conditions  | Website disclaimer  | Cancellation and Refund Policy  | Shipping & Delivery Policy