Force user to fill all fields before enabling form submit

前端 未结 12 2045
忘掉有多难
忘掉有多难 2021-02-07 00:49

I have a form containing various fields.

See jsFiddle demo.

My aim is to enable the submit button only when the user has filled in all fields.

So far,

12条回答
  •  花落未央
    2021-02-07 01:38

    Here's how you can do it:

    $(document).ready(function () {
        var $inputs = $("#new_tide input:not([type=hidden]), #new_tide textarea");
    
        $inputs.on("input change", function () {
            valid = true;
            $inputs.each(function () {
                valid *= this.type == "radio" ? this.checked : this.value != "";
                return valid;
            });    
            $("#subnewtide").prop("disabled", !valid);
        });
    });
    
    
    Title:
    Description:
    Tag:
    Category: Animation Hidden:

提交回复
热议问题