In my form, I aim to disable the submit button until all fields are selected.
Open this jsfiddle and do the following in this order:
- Write something in the
Description
field. - Choose a
category
.
This will enable the submit button if the Title
field is empty. How can I change the code so that the submit button remains disabled until all fields are filled.
jQuery code:
jQuery("input[type='text'], textarea").on("keyup", function(){
if(jQuery(this).val() != "" && jQuery("textarea").val() != "" && jQuery("input[name='category']").is(":checked") == true){
jQuery("#subnewtopic").removeAttr("disabled");
} else {
jQuery("#subnewtopic").attr("disabled", "disabled");
}
});
jQuery("input[name='category']").on("change", function(){
if(jQuery(this).val() != "" && jQuery("textarea").val() != "" && jQuery("input[name='category']").is(":checked") == true){
jQuery("#subnewtopic").removeAttr("disabled");
} else {
jQuery("#subnewtopic").attr("disabled", "disabled");
}
});