Validating Empty Fields with Auto-focus using JQuery

PHOTO EMBED

Tue Dec 28 2021 13:34:20 GMT+0000 (UTC)

Saved by @jalimpia #jquery

    /*Validate Fields*/
    $( document ).ready(function() {
        $(document).on("click", "#bottom_button", function(e) {
            e.preventDefault();
            var flag = true;
            $(':input[name^=items]').each(function() {
                if(!$(this).is(":hidden")){
                    if ($(this).val() == null || $(this).val() == '') {
                        $(this).css('border','2px solid #e74c3c');
                        $(this).focus();
                        flag = false;
                    }else{
                        $(this).css('border','1px solid #80BDFF');
                    }
                }
            });
            if(flag==true){
                $("#submit_proposal").submit();
            }
        });
    });
content_copyCOPY