JSFiddle - React, Tailwind, and code Playground

by kikkiraj

HTML

<form method="post" action="" id="myForm">
    <input type="text" class="partialProdAmt" value="0" />
    <input type="text" class="partialProdAmt" value="0" />
    <input type="text" class="partialProdAmt" value="0" />
    <input type="text" class="partialProdAmt" value="0" />
    <input type="button" value="Send" id="submit" />
</form>
<div class="msg"></div>

JavaScript

$("#submit").on("click", function () {
    var isValid = [];
    var chkForInvalidAmount = [];
    $('.partialProdAmt').each(function () {
        if ($.trim($(this).val()) <= 0) {
            isValid.push("false")
        } else {
            isValid.push("true")
        }
        if ($.isNumeric($(this).val()) == true) {
            chkForInvalidAmount.push("true")
        } else {
            chkForInvalidAmount.push("false")
        }
    });
    if ($.inArray("true", isValid) > -1) {
        $(".msg").html("Amounts Entered More than $0 ")
        return false;
    } else {
        $(".msg").html("Atlest One Amount is required in any field ")
        return false;
    }
    if ($.inArray("false", chkForInvalidAmount) > -1) {
        $(".msg").html("Please enter Correct format ")
        return false;
    } else {
        $(".msg").html("All Looks good")
        return false;
    }
});