JavaScript > Arithmetic Operators

Division remainder in JavaScript

How to get the division remainder in JavaScript?


To get the division remainder number in JavaScript, we can follow this approach.

<script>
        function DivisionRemainder() {
            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="btnDivisionRemainder" value="Submit" onclick="DivisionRemainder()" />

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

OUTPUT

 Views: 5296 | Post Order: 16



Write for us






Hosting Recommendations