JavaScript > Arithmetic Operators

Decrement in JavaScript

How to easily decrement the number by one in JavaScript?


To decrement number by one  in JavaScript, we can follow this approach.

   <script>
        function Decrement() {
            var a = parseInt(document.getElementById("txtA").value);
            a--;
            alert(a);
        }
    </script>
    
    Enter two digit:
    <input type="text" id="txtA" name="txtA" />
    <input type="button" name="btnDecrement" value="Submit" onclick="Decrement()" />

In the above code snippet, we have One textbox. On click of button, we are calling the Decrement function that decreases the enterd number by one and show result in the alert.

OUTPUT

 Views: 4375 | Post Order: 18



Write for us






Hosting Recommendations