JavaScript > Arithmetic Operators

Multiply in JavaScript

How to multiply numbers in JavaScript?

To multiply two or more numbers in JavaScript, we can follow this approach.

        function Multiply() {
            var a = document.getElementById("txtA").value;
            var b = document.getElementById("txtB").value;
            var result = parseInt(a) * parseInt(b);
    Enter two digit:
    <input type="text" id="txtA" name="txtA" />
    <input type="text" id="txtB" name="txtA" />
    <input type="button" name="btnMultiply" value="Submit" onclick="Multiply()" />

In the above code snippets, on click of Submit button Multiply function executes. In this function, both textbox values are retrieved and multiplied after parsing their values. At last the result is shown in the alert box.


 Views: 17105 | Post Order: 14

Write for us

Hosting Recommendations