I have two input fields one for advance payment and other for full payment, which are fetched from the database in array.
If onchange
or keyup
the advance payment is greater than full payment, Then the advance payment should not be entered or should be equal to full payment.
I am trying with this code
<input type="text" value="<?php echo $full_payemnt; ?>" id="full_payment_<?php echo $i; ?>">
<input type="text" id="advance_payment_<?php echo $i; ?>" class="advance">
$('.advance').on('change keyup blur', function(e){
var fullPay = $('#full_payment_'+id[1]).val();
var advancePay = $('#advance_payment_'+id[1]).val();
console.log( parseInt(advancePay) > parseInt(fullPay))
if (parseInt(advancePay ) > parseInt(fullPay)) {
e.preventDefault();
$('#advance_payment_'+id[1]).val(fullPay);
}
});
Create a message to display for field input that is not valid 1 Select the field that needs a message for input that is not valid. The field should already have a validation rule. 2 On the Fields tab, in the Field Validation group, click Validation, and then click Field Validation Message. 3 Enter an appropriate message. ...
A typical requirement is to validate an input value against another another input value on a screen. A classic example is a form with two input controls: Start date and End date. In this situation, we have to ensure that End Date is greater than or equal to Start Date.
Field properties Some field properties restrict data input. For example, the Field Sizeproperty of a field restricts input by limiting the amount of data. You can also use the Validation Ruleproperty to require specific values, and the Validation Textproperty to alert your users to any mistakes.
The validation number should be greater than 0. I am not submitting the form to the SharePoint list, if the line item quantity is 0. I want to visually prompt the user that they need to add quantity value greater than 0. Let me know so I can guide you with the best possible suggestion.
Here is an example of how you can do it.
var $full = $('[name=full]');
var $adv = $('[name=adv]');
$adv.on('keyup keydown', function(e) {
var fullPay = parseInt($full.val(), 10);
var advPay = parseInt($adv.val(), 10); //tell the parser it is base 10
if (advPay > fullPay &&
e.keyCode !== 46 // keycode for delete
&&
e.keyCode !== 8 // keycode for backspace
) {
e.preventDefault();
$adv.val('');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="number" name="full" />
<input type="number" name="adv" />
Try this, I think you want this.
$('.advance').on('change keyup blur', function(e){
id_arr = $(this).attr('id');
id = id_arr.split("_");
var fullPay = $('#fullPayment_'+id[1]).val();
var advancePay = $('#advancePayment_'+id[1]).val();
if ($(this).val() > parseInt(fullPay)) {
e.preventDefault();
$(this).val(fullPay);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<tr>
<input type="text" value="12" id="fullPayment_1">
<input type="text" id="advancePayment_1" class="advance">
</tr>
<br>
<tr>
<input type="text" value="19" id="fullPayment_2">
<input type="text" id="advancePayment_2" class="advance">
</tr>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With