Subtraction with JavaScript

Source: Internet
Author: User

<! DOCTYPE html>
<meta charset= "UTF-8" >
<title></title>
<style>

</style>
<body>
<div>
<input type= "text" size= "ten" id= "Num1"/>
<select name= "sel" id= "sel" >
<option>+</option>
<option>-</option>
<option>*</option>
<option>/</option>
<option>%</option>
</select>
<input type= "text" size= "ten" id= "num2"/>
<button onclick= "Myadd ()" >=</button>
<input type= "text" size= "ten" id= "num3" readonly/>
<div id= "div11" style= "color:red; font-size:12px; ">

</div>
</div>
<script>
function Myadd () {
var div11 = document.getElementById (' div11 ');
var num1 = document.getElementById (' num1 ');
var num2 = document.getElementById (' num2 ');
var num3 = document.getElementById (' num3 ');
var sel = document.getElementById (' sel ');

div11.innerhtml = "";
if (num1.value== "" | | isNaN (num1.value) | | num2.value== "" | | IsNaN (num2.value)) {
div11.innerhtml = ' input content is not a number ';
}else{
if (sel.value== ' + ') {
Num3.value = (parsefloat (num1.value) + parsefloat (num2.value)). toFixed (2);
}else if (sel.value== '-') {
Num3.value = (parsefloat (num1.value)-parsefloat (Num2.value)). toFixed (2);
}else if (sel.value== ' * ') {
Num3.value = (parsefloat (num1.value) * parsefloat (Num2.value)). toFixed (2);
}else if (sel.value== '/') {
if (parsefloat (num2.value) ==0) {
div11.innerhtml = ' dividend cannot be 0 ';
}else{
Num3.value = (parsefloat (num1.value)/parsefloat (Num2.value)). toFixed (2);
}
}else if (sel.value== '% ') {
if (parsefloat (num2.value) ==0) {
div11.innerhtml = ' dividend cannot be 0 ';
}else{
Num3.value = (parsefloat (num1.value)% parsefloat (num2.value)). toFixed (2);
}
}
}
}
</script>
</body>

Subtraction with JavaScript

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.