Initially my button is in disabled mode. When a user selects both start and end dates only then it should be enabled to download.
The below code enables the button when only start or end date is selected. How could I enable download button only when both inputs are not empty by applying class $('#btn_download').attr('class','btn-general');?
//enable 'Download' button only if Start-End dates are not empty
var enableDisableBtn = function(){
var startVal = $('#datepicker_start').val().trim();
var endVal = $('#datepicker_end').val().trim();
var disableBtn = startVal.length == 0 || endVal.length == 0;
$('#btn_download').attr('disabled',disableBtn);
$('#btn_download').attr('class','btn-general');
}
$('#datepicker_start').datepicker({
enableDisableBtn();
});
$('#datepicker_end').datepicker({
enableDisableBtn();
});
<button class="btn-general disabled" id="btn_download" type="button">
<span class="glyphicon glyphicon-download-alt" style="margin-right:5px;"></span>
Download
</button>
.btn-general {
background-color: #6eb8d9;
color: #fff;
border: medium none;
border-radius: 6px;
cursor: pointer;
display: inline-block;
font-size: 15px;
line-height: 1.4;
padding: 6px 15px;
text-align: center;
vertical-align: middle;
white-space: nowrap;
}
.btn-general.disabled {
background-color: #5bc0de;
color: #fff;
pointer-events:none;
cursor:not-allowed;
opacity:0.40;
}
enableDisableBtnwhen initializingdatepicker?