简体   繁体   中英

How to perform addition of 2 numbers with asp.net using web api and Javascript without using JQuery

I know there are multiple tutorials for addition of 2 numbers, but my question is how to do addition of 2 numbers, where the system displays the addition of 2 numbers on entering the values in the input box. eg: value1: 5 value2: 10 result:

the system should display result as 15 as i enter value2 input box.

How is it possible to do using web api with C#? and without using jquery.

Sure..

function propertyChange(ev) {            
    var request;
    if (window.XMLHttpRequest) {
        //New browsers.
        request = new XMLHttpRequest();
        var formData = new FormData(document.forms.Property);
    }
    if (request != null) {
        var url = "Calculator/NetWorth";
        request.open("POST", url, false);
        request.send(formData)
        
    }

    totalAssets.value = request.response;
}
html code below

<form name="Property"  >
  <p>
      <br/><br />
  </p>
    <table>
        <tr>
            <td><h2>Property</h2></td>
        </tr>
        <tr>
            <td>  Property1  </td>
            <td> 
                <input type="number" onchange="propertyChange(event)"
                       id="property1" name="property1" min="0"
                       value="1500.00"  />
            </td>
        </tr>
        <tr>
            <td>  Property2  </td>
            <td>
                <input type="number" id="property2" name="property2"
                       min="0" value="4100.00" 
                       onchange="propertyChange(event)" />
            </td>
        </tr>
        <tr>
            <td>  Total Expenditure </td>
            <td> <input type="text" id="totalExpenditure"
                        name="totalExpenditure" contenteditable="false" />
            </td>
        </tr>
    </table>
</form>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM