Completely Free .NET word API

Resources » TypeScript » Scripting Languages » Javascript

Simple calculator

Updated: Category: Javascript
Author: Member Level: SilverPoints: 7

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)

Did you like this resource? Share it with your friends and show your love!

Responses to "Simple calculator"

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


Post 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:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)

    Type the numbers and letters shown on the left.

    Submit Article     Return to Article Index
    Subscribe to Subscribers
    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Talk to Webmaster Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India