Enable / disable dropdown in jquery

I'm new to jQuery and I want to enable and disable the dropdown using the checkbox. This is my html:

<select id="dropdown" style="width:200px"> <option value="feedback" name="aft_qst">After Quest</option> <option value="feedback" name="aft_exm">After Exam</option> </select> <input type="checkbox" id="chkdwn2" value="feedback" /> 

What jQuery code do I need to do? Also look for good jQuery documentation / tutorial.

+52
jquery drop-down-menu
Oct 09 2018-11-11T00:
source share
8 answers

Here is one way that I hope is easy to understand:

http://jsfiddle.net/tft4t/

 $(document).ready(function() { $("#chkdwn2").click(function() { if ($(this).is(":checked")) { $("#dropdown").prop("disabled", true); } else { $("#dropdown").prop("disabled", false); } }); }); 
+123
09 Oct '11 at 11:52
source share

Try it -

 $('#chkdwn2').change(function(){ if($(this).is(':checked')) $('#dropdown').removeAttr('disabled'); else $('#dropdown').attr("disabled","disabled"); }) 
+7
Oct 09 '11 at 11:54
source share

I am using jQuery> 1.8 and this works for me ...

 $('#dropDownId').attr('disabled', true); 
+4
Oct 24 '14 at 20:16
source share

try it

  <script type="text/javascript"> $(document).ready(function () { $("#chkdwn2").click(function () { if (this.checked) $('#dropdown').attr('disabled', 'disabled'); else $('#dropdown').removeAttr('disabled'); }); }); </script> 
+1
Oct 09 '11 at 11:54
source share

To enable / disable -

 $("#chkdwn2").change(function() { if (this.checked) $("#dropdown").prop("disabled",true); else $("#dropdown").prop("disabled",false); }) 

Demo - http://jsfiddle.net/tTX6E/

+1
09 Oct '11 at 11:57
source share
 $("#chkdwn2").change(function(){ $("#dropdown").slideToggle(); }); 

Jsfiddle

0
09 Oct '11 at 11:48
source share
 $("#chkdwn2").change(function() { if (this.checked) $("#dropdown").prop("disabled",'disabled'); }) 
0
Sep 08 '14 at 10:54 on
source share
 $(document).ready(function() { $('#chkdwn2').click(function() { if ($('#chkdwn2').prop('checked')) { $('#dropdown').prop('disabled', true); } else { $('#dropdown').prop('disabled', false); } }); }); 

using .prop in the if .

0
Oct 13 '14 at 9:15
source share



All Articles