Force user to fill all fields before enabling form submit

前端 未结 12 2030
忘掉有多难
忘掉有多难 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:46

    Use this html
    HTML:
    Title: ## Description: Tag: Category: Animation
    validation code:
    //on each key up function intiate the function validate
        jQuery("input[type='text']").on("keyup", function () {
            validate();
        });
        jQuery("#description").on("keyup", function () {
            validate();
        });
    
        function validate(){
         jQuery("input[type='text']").each(function(){
    
            if (jQuery(this).val() != "" )
            {
                if((jQuery("#description").val() !="") && (jQuery("#cate").is(':checked')))
                {
    
                    jQuery("#subnewtide").removeAttr("disabled"); 
                }
                else {
                    jQuery("#subnewtide").attr("disabled", "disabled");
                }
            } 
        });
        }
        
    you can find the fiddle in : https://jsfiddle.net/s8uv2gkp/

提交回复
热议问题