Tools used Visual Studio 2019, Asp.net core 5.0 (.net 5.0)
I have 3 textboxes: Pricex, Subtractx and Sumx.
What i want is if the Subtractx value gets bigger or equal to Price value, then Subtract = Price and Sum = Price.
If it is possible, can this be done directly in C#?
Im trying this JS code but its not working
<script>
$(function () {
getSum();
})
$("#Subtractx").keyup(function () {
getSum();
})
function getSum() {
if ($("#Subtractx").val() >= $("#Pricex").val())
{
$("#Subtractx").val($("#Pricex").val());
var sum = /*parseInt($("#Rows_Qty").val()) * */parseInt($("#Pricex").val()) - parseInt($("#Subtractx").val())
$("#SumX").val(sum);
}
var sum = /*parseInt($("#Rows_Qty").val()) * */parseInt($("#Pricex").val()) - parseInt($("#Subtractx").val())
$("#SumX").val(sum);
}
</script>
Below is a working demo, you can check it.
<label>Price</label>
<input type="number" id="Pricex"/>
<label>Subtract</label>
<input type="number" id="Subtractx"/>
<label>Sum</label>
<input type="number" id="SumX"/>
@section Scripts
{
<script>
$(function () {
getSum();
})
$("#Subtractx").keyup(function () {
getSum();
})
function getSum() {
var x = parseFloat($("#Subtractx").val());
var y = parseFloat($("#Pricex").val());
if (x >= y) {
$("#Subtractx").val($("#Pricex").val());
var z = parseFloat($("#Subtractx").val());
var sum = (y - z).toFixed(2);
$("#SumX").val(sum);
}
else {
var sum = (y - x).toFixed(2)
$("#SumX").val(sum);
}
}
</script>
}
Test result:
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.