JavaScript > Assignment Operators

Subtract and assign in JavaScript

How to subtract and assign value in JavaScript?


To subtract and assign value in JavaScript, we can follow this approach.

  <script>
    function Subtractassignvalue() {
        var a = document.getElementById("txtA").value;
        var result = 5;
        result -= parseInt(a);
        alert(result);
    }
    </script>

Enter two digit:
    <input type="text" id="txtA" name="txtA" />
    <input type="button" name="btnSubtractassignvalue" value="Subtract & Assign value"  onclick="Subtractassignvalue()" />

In the above code snippet, we have one text box. On click of button, we are calling the Subtractassignvaluefunction that subtracts and assign the number and show result in the alert. Here also we are parsing the value of text box as Integer and subtracting the way we had done in Add and assign.

OUTPUT

 Views: 5182 | Post Order: 20



Write for us






Hosting Recommendations