Unkown Kid
Unkown Kid

Reputation: 265

Select2 Disable other Select2 based on option

I have two select2 options

enter image description here

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');
  }
}

Upvotes: 0

Views: 60

Answers (1)

Tymur Valiiev
Tymur Valiiev

Reputation: 729

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

Upvotes: 1

Related Questions