Division of two numbers- Using JavaScript statement we can perform arithmetic operations like +, -, *, /
E.g.
Check Output:
E.g.
<html>
<head>
<title>Division of two numbers</title>
</head>
<body>
<center>
Divide two Numbers
<form name="form1">
Enter First number: <input type="text" name="val1">
Enter Second number: <input type="text" name="val2">
<input type="button" onclick="valadd()" value="Divide">
</form>
<script language="Javascript">
function valadd()
{
var a=document.form1.val1.value;
var b=document.form1.val2.value;
if(a.length==0 || b.length==0)
{
alert("Please enter all required values")
}
else if(isNaN(a) || isNaN(b))
{
alert("Only number/s allowed in both fields")
}
else
{
var c= eval(a)/ eval(b);
alert("Result is: " + c + "\nIf you like this post then please \nshare it using share buttons \ngiven below");
}
}
</script>
</center>
</body>
</html>
Related Topics:
- JavaScript Introduction
- Variables in JavaScript
- JavaScript Function
- Accessing JavaScript Function
- Creating JavaScript interactive form
- Accessing form field value
- Creating interactive form login webpage
- Networking Fundamentals
- TCP/IP and Internet addressing
- Internet Working
- Internet Working Servers
- Concept and need for web publishing
- Web languages
- Javascript Control Structure
- Checking Text is Letter/s
- Checking Text is Number/s
- Checking Textbox is Empty or not
- Addition of two numbers
- Subtraction of two numbers
- Multiplication of two numbers
- Division of two numbers
- Form field validations
- Email validation