Simple calculator

Implement a simple calculator of your own in your website , use thoe following code inside your " body " tag , here functions for addition , subtraction , multiplication and division are written seperatly and is called when the appropriate button is pressed .

<table border=2 cellpadding=3 bgcolor=#E6E9EA><tr><td>
<div align="center"><b>Enter 2 Numbers:</b><br>
<input type=text size=5 name=num1>
<input type=text size=5 name=num2></div></tr></td><tr><td>

<div align="center"><b>Click on a Function</b><br>
<input type=button name=a1 value=" + " onclick="addFields(this.form)">
<input type=button name=a2 value=" - " onclick="subFields(this.form)">
<input type=button name=a3 value=" x " onclick="mulFields(this.form)">
<input type=button name=a4 value=" / " onclick="divFields(this.form)"></div>

<div align="center"><B>The Answer is:</B><br>
<input type="text" size=8 name="result"></div></td></tr><tr><td>
<div align="center"><input type=reset name=clear value="clear fields"></div></td></tr></table>

<script language="javascript">

function addFields(form) {
var sum = eval(form.num1.value) + eval(form.num2.value)
function subFields(form) {
var sub = eval(form.num1.value) - eval(form.num2.value)
function mulFields(form){
var mul = eval(form.num1.value) * eval(form.num2.value)
function divFields(form) {
form.result.value = eval(form.num1.value) / eval(form.num2.value)


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: