JavaScript > Arithmetic Operators

Division in JavaScript

How to divide numbers in JavaScript?

To divide number in JavaScript, we can follow this approach.

        function Division() {
            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="btnDivision" value="Submit" onclick="Division()" />

In the above code snippet, we have two textboxes. On click of button, we are calling the Division function that divide the numbers and show result in the alert.


 Views: 752 | Post Order: 15

Write for us