I want to enable/disable a dropdown field based on the value of other dropdown field in the sharepoint 2013 form.I know that it is possible using jquery but i dont know how to write? help me to get the correct code.
3 Answers
Suppose the id of two dropdown controls you have is "ddl1" and "ddl2". So the code snippet for your requirement will be
$(function() {
$("#ddl1").change(function() {
if ($(this).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. And will enable it if you select another value. Make sure you have included jquery reference and assigned id's to your fields.
-
1You should use .prop() for disabled rather than .attr(). Commented Oct 20, 2013 at 3:38
-
Almost there. It should be $("#ddl2").prop("disabled", true); Properties are binary: they are either on or off, thus true or false. As of jQuery 1.6, you can't use .attr(). See: api.jquery.com/prop Commented Oct 20, 2013 at 12:53
Use javascript, if you want to do it in client side.
function DisableDropdown(id1){
var elementID;
elementID = document.getElementById(id1);
elementID.disabled = true;
}
on selecting any values from dropdown1 it will disable dropdown2 and vice versa.
$(function() {
$("#dropdown1").change(function() {
$("#dropdown2").prop("disabled", true);
});
$("#dropdown2").change(function() {
$("#dropdown1").prop("disabled", true);
});
});