Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable/Disable a dropdownbox in jquery

I am new to jQuery and I want to enable and disable a dropdown list using a 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 this? Also searching for a good jQuery documentation/study material.

like image 466
ARUN P.S Avatar asked Oct 09 '11 11:10

ARUN P.S


People also ask

How do I disable a specific value in a dropdown?

In this post, I will show you how you can disable specific items of the DropDown/ComboBox/Select element using jQuery. To disable any item, just need to add attribute "disabled" with value "disabled" to the list item.

How do you enable disable a dropdown based on value in another dropdown in jQuery?

val() == "<yourValue>") { $("#ddl2"). prop("disabled", true); } else $("#ddl2"). prop("disabled", false); }); }); The above code will disable the "ddl2" dropdown on select of a particular value in first dropdown.


1 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);      }  }); }); 
like image 90
Kris Krause Avatar answered Oct 03 '22 08:10

Kris Krause