change select to disabled using a checkbox


Topic: change select to disabled using a checkbox

kaz pro premium asked 2 months ago

Hi

I hope you are well.

I have a checkbox which when checked should make the select field disabled but for some reason, I can't get it working. It works fine to disable an input type of text but not a select.

I have created a snippet so speed things up:https://mdbootstrap.com/snippets/jquery/kazosman/2186925

Can you please advise?

Many thanksKaz


kaz pro premium answered 2 months ago

Hi Tomek

I hope you are well.

Thank you for your help.

One last thing please - if the checkbox is already checked when the page loads is it possible to have the select disabled at that time?

Thanks Kaz


Tomek Makowski staff commented 2 months ago

Of course do the same thing but on window.onload event


Tomek Makowski staff answered 2 months ago

Hi

All you have to do is just reinitialize material select after changes. Then script will render it with new value like disabled="true" .

https://mdbootstrap.com/snippets/jquery/tomasz-makowski/2192428?view=project#js-tab-view

Regards


kaz pro premium answered 2 months ago

Hi Tomek

I hope you are well.

Thank you very much for your answer.

Kind regards Kaz


kaz pro premium answered 2 months ago

Hi

I hope you are well.

I have expanded the example snippet as I need to disable the select when the checkbox is checked and enable the select when the checkbox is not checked.The not checked part doesn't work - can you please take a look:

https://mdbootstrap.com/snippets/jquery/tomasz-makowski/2192428?view=project#js-tab-view

Also if the checkbox loads in a checked state - is it possible to have the select disabled at the page load time?

ThanksKaz


Please insert min. 20 characters.
Status

Answered

Specification of the issue
  • User: Pro
  • Premium support: Yes
  • Technology: jQuery
  • MDB Version: 4.19.0
  • Device: n/a
  • Browser: firefox and chrome
  • OS: Ubuntu
  • Provided sample code: No
  • Provided link: Yes
Tags