To multiply two or more numbers in JavaScript, we can follow this approach.
<script> function Multiply() { var a = document.getElementById("txtA").value; var b = document.getElementById("txtB").value; var result = parseInt(a) * parseInt(b); alert(result); } </script> 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.
OUTPUT
Views: 17537 | Post Order: 14