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="2" />
    <input type="text" class="partialProdAmt" value="1" />
    <input type="text" class="partialProdAmt" value="1" />
    <input type="button" value="Send" id="submit" />
</form>
<div class="results"></div>

JavaScript

$("#submit").on("click", function () {
    var isValid = [];
    var chkForInvalidAmount = [];
    var results = $(".results").html();
    $('.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")
        }
    });
    console.log(chkForInvalidAmount)
    console.log($.inArray("true", chkForInvalidAmount))
    if ($.inArray("true", isValid) > -1) {
        results.push("Amounts Entered More than $0 ")
    } else {
        results.push("Atlest One Amount is required in any field ")
    }
    if ($.inArray("false", chkForInvalidAmount) > -1) {
        results.push("Please enter Correct format ")
    } else {
        results.push("All Looks good")
    }
});