Last updated on January 22nd, 2016 at 03:28 am

VN:F [1.9.22_1171]
Rating: 7.3/10 (38 votes cast)

Javascript calculator with basic arithmetic operations

This is a simple javascript that performs basic arithemetic operations like Addition, Subtraction, Division, Multipication and Modulus. Just copy paste the below script in to an html file and run on any browser to see the working.

Check out Advance Calculator With Memory Function Using Javascript.

<script language="javascript" type="text/javascript">
function multiply(){
a=Number(document.my_cal.first.value);
b=Number(document.my_cal.second.value);
c=a*b;
document.my_cal.total.value=c;
}
</script>

<script language="javascript" type="text/javascript">
function addition(){
a=Number(document.my_cal.first.value);
b=Number(document.my_cal.second.value);
c=a+b;
document.my_cal.total.value=c;
}
</script>

<script language="javascript" type="text/javascript">
function subtraction(){
a=Number(document.my_cal.first.value);
b=Number(document.my_cal.second.value);
c=a-b;
document.my_cal.total.value=c;
}
</script>

<script language="javascript" type="text/javascript">
function division(){
a=Number(document.my_cal.first.value);
b=Number(document.my_cal.second.value);
c=a/b;
document.my_cal.total.value=c;
}
</script>

<script language="javascript" type="text/javascript">
function modulus(){
a=Number(document.my_cal.first.value);
b=Number(document.my_cal.second.value);
c=a%b;
document.my_cal.total.value=c;
}
</script>

<!-- Opening a HTML Form. --> 
<form name="my_cal">

<!-- Here user will enter 1st number. --> 
Number 1: <input type="text" name="first"> 
 

<!-- Here user will enter 2nd number. --> 
Number 2: <input type="text" name="second"> 


<!-- Here result will be displayed. --> 
Get Result: <input type="text" name="total"> 

<input type="button" value="ADD" onclick="javascript:addition();">
<input type="button" value="SUB" onclick="javascript:subtraction();">
<input type="button" value="MUL" onclick="javascript:multiply();">
<input type="button" value="DIV" onclick="javascript:division();">
<input type="button" value="MOD" onclick="javascript:modulus();">
</form>
VN:F [1.9.22_1171]
Rating: 7.3/10 (38 votes cast)

Leave a Reply

Your email address will not be published. Required fields are marked *