I have two select elements and I want to disable submit button until both is has value.
I did some search and I found one nice code which works on old jQuery. The new version need update to work on jQuery 3.2.1 which my website currently uses.
I hope someone will provide me explanation why my code works perfectly on 1.5.2 and won't work on 3.2.1 version of jQuery.
Here is basic HTML of two selects, so I want to enable button only when both select has some value
$('#btnProceed').attr('disabled', 'disabled');
function updateFormEnabled() {
if (verifyAdSettings()) {
$('#btnProceed').attr('disabled', '');
} else {
$('#btnProceed').attr('disabled', 'disabled');
}
}
function verifyAdSettings() {
if ($('#buyoption').val() != '' && $('#selloption').val() != '') {
return true;
} else {
return false
}
}
$('#buyoption').change(updateFormEnabled);
$('#selloption').change(updateFormEnabled);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<form action="" method="POST" id="postForm">
<div class="row">
<div class="col-md-9 register-right">
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">
<h3 class="register-heading">
<div class="row register-form">
<div class="col-md-12">
<div class="form-group">
<select class="form-control" name="buy" id="buyoption">
<option class="hidden" selected disabled value="">Please select what you want</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
</div><label for="buy"><b>YOU </b></label>
<div class="form-group">
<select class="form-control" name="sell" id="selloption">
<option class="hidden" selected disabled value="">Please select what you to</option>
<option value="1">1</option>
<option value="2">2</option>
</div><input type="submit" class="btnRegister" id="btnProceed" value="NEXT" /> </div>
</div>
</div>
</div>
</div>
</div>
</form>