0

https://jsfiddle.net/xrxjoaqe/

I don't know what's wrong with the bootstrap inline validation files... Even after entering all the values, the submit button is not getting enabled.

$('#registerbutton').attr('disabled', 'disabled');

function updateFormEnabled() {
  if (verifyAdSettings()) {
    $('#registerbutton').attr('disabled', '');
  } else {
    $('#registerbutton').attr('disabled', 'disabled');
  }
}

function verifyAdSettings() {
  if ($('#b2b_service_type').val() != '') {
    return true;
  } else {
    return false
  }
}

$('#b2b_service_type').change(updateFormEnabled);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form accept-charset="UTF-8" method="post" role="form" id="bookform" data-toggle="validator" enctype="multipart/form-data">
  <div class="form-group col-md-6 col-xs-6 has-feedback" style="padding:5px">
    <input id="b2b_customer_name" name="b2b_customer_name" class="form-control input-lg headerform" type="text" required placeholder="Your Name *" pattern="^[_A-z\s]{3,}$" data-error="Please enter atleast 3 alphabets">
    <div class="help-block with-errors"></div>
  </div>
  <div class="form-group col-md-6 col-xs-6 has-feedback" style="padding:5px">
    <input id="b2b_cust_phone" name="b2b_cust_phone" type="tel" class="form-control input-lg headerform" type="tel" maxlength="10" placeholder="Mobile Number. *" pattern="^[789]\d{9}$" data-error="Please enter a valid mobile number" required>
    <p class="help-block with-errors"></p>
  </div>
  <div class="form-group col-md-6 col-xs-6 has-feedback" style="padding:5px">
    <select id="b2b_service_type" name="b2b_service_type" class="form-control input-lg headerform status" required>
      <option value="" disabled="" selected="" hidden="">Service Type</option>
      <option value="22">something</option>
      <option value="34">Another</option>
    </select>
    <p class="help-block with-errors"></p>
  </div>
  <button id="registerbutton" type="submit" class="btn btn-xl submit" disabled>Submit</button>
  </div>
  <!-- Book div -->

2 Answers2

0

From the fiddle / code provided, it appears you are trying to:

  • enable the submit button when the combo changes

The fiddle doesn't work as you've not included jquery in the javascript options and the one you've included (via script src) is not being loaded as it's not https (always check the browser console window - it shows an http error and '$ is not defined'.

Fixing the jquery link (either of the two) still doesn't let it work, because you've used attr

Change this to prop

$('#registerbutton').prop('disabled', 'disabled');

function updateFormEnabled() {
    if (verifyAdSettings()) {
        $('#registerbutton').prop('disabled', '');
    } else {
        $('#registerbutton').prop('disabled', 'disabled');
    }
}

Updated fiddle: https://jsfiddle.net/xrxjoaqe/4/

freedomn-m
  • 27,664
  • 8
  • 35
  • 57
0

Please be sure & finish all your edits before posting a question. Try this out. This will help you!

<button id="registerbutton" type="submit" class="btn btn-xl submit" disabled="disabled">Submit</button>

Use removeAttr

function updateFormEnabled() {
          if (verifyAdSettings()) {
            $('#registerbutton').removeAttr('disabled');
          } else {
            $('#registerbutton').attr('disabled', 'disabled');
          }
        }