In this program, we are going to learn about how to multiply and divide two numbers using JavaScript, where the two numbers are entered by the user using a textbox.
Before reading this code you should know about.
- HTML Input
- HTML DOM
- Javascript Function
- HTML Button
- HTML onclick event.
HTML Code
<!DOCTYPE HTML>
<HTML>
<body>
<h3>Javascript program to calculate the multiplication and division of two numbers</h3>
<div>
Enter first number :<input type="text" id="Num1"><br />
Enter Second number:<input type="text" id="Num2"><br />
<button onclick="multiply()">Multiply</button>
<button onclick="divide()">Divide</button>
<p>The Multiplication and division of two numbers is :</p>
<span id="result"></span>
</div>
</body>
</HTML>
CSS Code
function multiply() {
var a = parseInt(document.getElementById("Num1").value);
var b = parseInt(document.getElementById("Num2").value);
var c = a * b;
document.getElementById("result").innerHTML = c;
}
function divide() {
var a = parseInt(document.getElementById("Num1").value);
var b = parseInt(document.getElementById("Num2").value);
var c = a / b;
document.getElementById("result").innerHTML = c;
}
When we hit multiply the output will look like this

When we hit divide the output will look like this
