I have two select2 options
I want to implement something like, if user click daily they can use the Select2 option of Days, But if they select Monthly then the another Select2 button will be disable. Can u check why my code isn't working.
{{ Form::select('type', $type, null, ['class' => 'form-control select2', 'onchange' => 'myFunction()', 'id' => 'recurring_type', 'required' => 'true', }}
{{ Form::select('days', $days, null, ['class' => 'form-control select2', 'id' => 'days', 'required' => 'true', }}
And this is the javascript
function myFunction() {
if($(this).val() === 'Daily') {
$('#days').select2('disable');
} else {
$('#days').select2('disable');
}
}
CodePudding user response:
My blind guess is that $(this).val()
is not equal to "Daily". You definatelly should recheck what you get with console.log($(this).val())
in beginning of myFunction
CodePudding user response:
function myFunction() {
const select = document.getElementById("recurring_type").value;
if(select == 'your option value') {
$('#recurring_type').select2('enable', false);
} else {
$('#recurring_type').select2('enable', true);
}
}