JavaScript > Assignment Operators

Divide and assign in JavaScript

How to divide and assign value in JavaScript?

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

        function Divisionassignvalue() {
            var a = document.getElementById("txtA").value;
            var result = 5;
            result /= parseInt(a);  //* result = result / 5;

    Enter two digit:
    <input type="text" id="txtA" name="txtA" />
    <input type="button" name="btnDivisionassignvalue" value="Division & Assign value"
        onclick="Divisionassignvalue()" />

In the above code snippet, we have one textbox. On click of button, we are calling the Divisionassignvaluefunction that divide and assign the number and show result in the alert. Same as previous post, the value of text box is being parsed into integer and being divided by 5.


 Views: 723 | Post Order: 22

Write for us