How To Calculate Two Numbers In JavaScript : sum, minus, duplication, division
Source Code:
http://1bestcsharp.blogspot.com/2017/01/javascript-addition-subtraction-multiplication-division.html
Javascript Tutorials For Beginners ➜ http://bit.ly/2k7NMWq
Javascript Course ➜ http://bit.ly/2IvBCFC
WEB-HOSTING (affiliate link) ➜ http://bit.ly/YtWebHost
visit our blog https://1bestcsharp.blogspot.com/
subscribe: http://goo.gl/nRjPKk
In This Javascript Tutorial we will See How To Calculate two Numbers ( Sum, Mutiplication, Division, Substraction )
Using Input Text, Button And Select Option For Math Operators In JS Using Netbeans Editor .
More Javascript Tutorials :
How to get value of selected radio button
How to append Value to an array
javascript images slider 1
Convert String To Number
JavaScript Show And Hide Input Password Text
change div class name in js
using checkbox with js
get And Set Value To An Input
Search Element In Array
Add Search Remove Array Element
Add HTML Table Row
Get Mouse Position
Calculator:
share this video: https://youtu.be/oDUjP4N_MtQ
Original source
32 responses to “JavaScript Calculate 2 Numbers Form Input Text – Addition, Subtraction, Multiplication, Division”
i add 2 more values in your code but it's showing "" nul "" . is it compulsory to add all values ? . how to fix it
bhai iska kasa banega ?
Example
a+b+c+d = e
e+ f= g
I DONNO IM DOING SOMETHING WRONG AND I CANT figure it here is my code please help me find the mistake in this
<!DOCTYPE html>
<html>
<head>
<meta name="viewpoint" content="width=device-width,initial-scale=1.0">
<title> calculator </title>
<script type="text/javascript">
function calculator() {
var n1 = parseInt (document getElementsById('n1').value);
var n2 = parseInt (document getElementsById('n2').value);
var oper = document getElementsById('operations').value;
if (oper==='+') {
var n2 = document.getElementsById('result').value=n1+n2;
}
if (oper==='-') {
var n2 = document.getElementsById('result').value=n1-n2;
}
if (oper==='/') {
var n2 = document.getElementsById('result').value=n1/n2;
}
if (oper==='x') {
var n2 = document.getElementsById('result').value=n1 x n2;
}
</script>
</head>
<body>
<form>
<input type="text" id="n1" placeholder="0">
<br>
<input type="text" id="n2" placeholder="0">
<select id="operations" /*disabled="operations"*/>
<option>+</option>
<option>-</option>
<option>/</option>
<option>x</option>
</select>
<br>
=
<br>
<input type="text" name="result" id="result" disabled="result">
<input type="button" name="GO" placeholder="GO" value="GO">
</form>
</body>
</html>
thanks it good job (y)
Would a switch statement work with all this?
thanks a lot 🙂
There's no need to write an if statement. You can also add them on this way. Here's the code.
function myFunction() {
var x = parseInt(document.getElementById("b1").value);
var y = parseInt(document.getElementById("b2").value);
var z = x + y;
document.getElementById("demo").innerHTML = z;
}
thanks a lot
thank u
Great Tutorial!!
You saved my a**
Thanks!!
please tell why it is not comming or tell othet methof
i wrote all the functions properly but it is not coming in internet explorer properly
Whats is the problem i input 5 and 3 and to multiply it became 15555???? What happened????
whats happen when i give else part after the if part?
Can we also make use of radio button instead of Dropbox ?will it work the same?
Very good bro… but its would be better if u added the voice.
It doesn't work
How do you set n2 to be a fix numeric value? So for example if you wanted to calculate the price of something: n1(qty) x n2($2.50)
Wow great! Would putting html elements around these such as divs have any impact?
Thanks bhai shukriya
Thanks
I like it
plz add this type video : I have a four textbox. first i give one number in first box textbox and other textbox we have value , then remaining three textbox automatically decrease the value and show that textbox 0
what do I do if I want add subtract to be buttons not a drop down? please help
Thanks bhai it helps alot
hi i look lot of videos but i cant find any thing which show how i can use code to add.
id, code, then amount,date, update,delete. next page,
if i want to know with code(serial number) how much amount have. or how many time i use this serial number
serial number of a card. as bank card. but there is lot of cards. so if i want to know how many time i use it to add money or take out money..
can you make a example of this ? THANKS
when I calculate 11.2 + 1.2 with the calculator the result is 12.399999999999999
is this a bug?
does this works if multiple dots(.) will be inputted? and how to make the dot appear only once?
this is my code.please help me … all box are appear but the function is not perform
<!DOCTYPE html>
<html>
<head>
<title>my java script page</title>
<script type="text/javascript">
function calc() {
var n1 = parseInt(document.getElementById('n1').value;)
var n2 = parseInt(document.getElementById('n2').value;)
var operaters=document.getElementById('operaters').value
if (operaters === '+') {
document.getElementById('result').value=n1+n2;
}
}
</script>
</head>
<body>
<input type="text" id='n1' ><br>
<input type="text" id='n2'><br>
<select id="operaters">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<button onclick="calc()">=</button>
<input type="text" id="result" >
</body>
</html>
Sir output is not shown. What can I do
hamasaaa khush rhooo ustaaad….
thank u ,u helped me alot
Is it JavaScript they use for the fantasy football websites to add your points up and everything? If so do u know a vid that shows how u do that? If not do u know what they use to do that.