JavaScript > Arithmetic Operators

Increment in JavaScript

How to easily increment the number by one in JavaScript?


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

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

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

OUTPUT

 Views: 5098 | Post Order: 17



Write for us






Hosting Recommendations