Reputation: 37
I need to check minimum amount is less than maximum amount from minimum input text and maximum input text in the jquery? How can i check ? Here is the method i check. Thanks.
$minimum_amt = $("#min_amt");
$maximum_amt = $("#max_amt");
$minimum_amt.on("change", function () {
if ($minimum_amt.val() == '.') {
alert("You can input only numeric number !");
}
if ($minimum_amt.val() > $maximum_amt.val()) {
$(':input[name="submitDiscount"]').prop('disabled', true);
}
else {
$(':input[name="submitDiscount"]').prop('disabled', false);
}
});
$maximum_amt.on("change", function () {
if ($maximum_amt.val() == '.') {
alert("You can input only numeric number !");
}
if ($minimum_amt.val() > $maximum_amt.val()) {
alert("Minimum Amount should be less than Maximum Amount !");
$(':input[name="submitDiscount"]').prop('disabled', true);
}
else {
$(':input[name="submitDiscount"]').prop('disabled', false);
}
});
Upvotes: 0
Views: 324
Reputation: 177950
$(".amt").on("input", function() {
var min = $.trim($("#min_amt").val()),
max = $.trim($("#max_amt").val()),
val = $.trim(this.value);
if (val && (val.indexOf(".") !=-1 || Math.floor(val) != val || !$.isNumeric(val))) {
alert("You can input only integers !");
$(this).val(val.substring(0,val.length-1))
$(this).focus();
return
}
var dis = (min.length==0 || max.length==0) || ((+min) > (+max));
$(':input[name="submitDiscount"]').prop('disabled',dis);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Min <input type="text" id="min_amt" class="amt" value="" />
Max <input type="text" id="max_amt" class="amt" value="" />
<input type="submit" name="submitDiscount" disabled "/>
Upvotes: 1