I try to compare two data values . one value get from database by ajax jquery call
function marketbuyshow(){
$.ajax({
type: "GET",
url: "/showmarketbuydata",
dataType: "json",
success: function (response) {
$("#balance").html("");
$.each(response.balancedata,function(key,item){
$('#balance').append('<span>'+item.mybalance+'</span>');
});
$("#balance").html("");
$.each(response.balancedata,function(key,item){
$('#balance').val(item.mybalance);
});
other one get from input value. I have this form for data input , price / amount / total input
<form>
<div class="title"> </div>
<div >Avaliable Balance : <span id="balance"></span></div>
<div >Avaliable Balance :<input type="text" id="balance" required class="total form-control" readonly /></div>
<div class="mb-3">
<label for="">Price</label>
<input type="text" id="price" required class="price form-control" />
</div>
<div class="mb-3">
<label for="">Amount</label>
<input type="text" id="amount" required class="amount form-control" />
</div>
<div class="mb-3">
<label for="">Total</label>
<input type="text" id="total" required class="total form-control" readonly />
</div>
<button type="submit" id="btnn" class="btn btn-primary marketbuy">Buy</button>
</form>
if total value greater than avaliable balance I want to disable buy button by jquery but this balance value not work with span tag . Although show data in frontend, it pass with empty string and cannot compare .So I change with input readonly to get data.
let balan = $('#balance').text();
console.log(balan);
let total = $('#total').val();
console.log(total);
if(total >balan){
console.log(yes);
}else{
console.log("total is less than ");
}
After I get balance value by changing input readonly value, I get data value but
I found two problems.
1- total value cannot update without reload page although it use jquery.
2-after reload , although total value appear in console, it cannot compare with balance, it has empty value cannot compare .
here is cosole after reload.
99944 trade:198:16
26666664 trade:199:16
total is less than
So How can solve this problem.
How can I compare this two values ,
can someone show me solution.
please check my codes,