Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
102 views
in Technique[技术] by (71.8m points)

javascript - Compare two input fields

Does anyone here how to compare two input fields using angularjs? I have two input fields, one is for balance input and it set as read-only and the second is the amount field where the user can enter the amount. For example, if the balance is 120 and when the user enters 150 in the amount field it will show an error message. Now the problem is when I enter an amount greater than the balance field, the error message of max in angular is not showing.

This is how I retrieve the data, it's working btw:

function view_payment(payment_sales_id) {
    var modal = $('#payment-sales-modal');
    $.ajax({
        type: 'POST', 
        url: url + 'GetPaymentDetailsById', 
        data: { payment_sales_id : payment_sales_id }, 
        dataType: 'json',
        success: function (data) {
            modal.modal({ backdrop: 'static', keyboard: false});
            modal.find($('#payment_sales_id')).val(payment_sales_id);
            modal.find($('#payment_net_amount')).val(data.sales_net_amount);
            modal.find($('#payment_balance')).val(data.sales_balance);
        }
    });
}

HTML

<div class="form-group">
    <label for="">Balance <small>*</small></label>
    <input type="text" id="payment_balance" name="payment_balance" placeholder="Balance" class="form-control" ng-model="payment_balance" ng-model="payment_balance" readonly>
</div>

<div class="form-group">
    <label for="">Amount <small>*</small></label>
    <input type="text" id="payment_amount" name="payment_amount" placeholder="Amount" class="form-control" ng-model="payment_amount" ng-pattern="/^[0-9]+.?[0-9]*$/" ng-max="payment_balance">
    <span ng-messages="formPayment.payment_amount.$error" ng-if="formPayment.payment_amount.$dirty">
        <strong ng-message="pattern" class="text-danger">Please type numbers only.</strong>
        <strong ng-message="max" class="text-danger">Please enter a value less than or equal to balance.</strong>
    </span>
</div>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.6k users

...