Skip to content Skip to sidebar Skip to footer

Enabling Button When All The Fields Are Filled Up

I am using knockout.js for data binding.Actually there is a form which some fields accepting name,number,email etc.Suppose if any one of the field is not filled and the save button

Solution 1:

something like this:

var formCompleted = false;
$('input[type="submit"]').attr('disabled','disabled');

$(":text, :file, :checkbox, select, textarea").change(function() {
  formCompleted = validateForm();   
  if(formCompleted){
    $('input[type="submit"]').removeAttr('disabled');
  }
});

functionvalidateForm() {
  var isValid = true;
  $('.form-field').each(function() {
    if ( $(this).val() === '' )
      isValid = false;
    });
  return isValid;
}

First you disable the button, on each form element change you check if it is filled out and then you remove the disabled attr. I haven't tested this, but it should get you started in the right direction.

Post a Comment for "Enabling Button When All The Fields Are Filled Up"