JavaScript > Arithmetic Operators

Division in JavaScript

How to divide numbers in JavaScript?


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

<script>
        function Division() {
            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="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.

OUTPUT

 Views: 4277 | Post Order: 15



Write for us






Hosting Recommendations