C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Javascript »

Simple calculator


Posted Date: 23 Sep 2008    Resource Type: Code Snippets    Category: Javascript
Author: MakeshMember Level: Silver    
Rating: 1 out of 5Points: 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 .


<form>
<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>
</td></tr><tr><td>

<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>
</form>
</td></table>

<script language="javascript">


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






Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Get URL of a page
Previous Resource: Enter Key Validation in javascript
Return to Discussion Resource Index
Post New Resource
Category: Javascript


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use