Enable/Disable a 'DropDownListFor' on a checkbox selection

I am working show the drop down values on selection of a check box. But with the below code, all different items that are present in the drop down coming directly.

Somehow the @Html.DropDownListFor is not working inside select tag, can anyone please help me to fix it?

Note: Checkbox toggle working perfectly.

Thank you,

.cshtml
<input type="checkbox" /> 
<p>check this box to escalate</p>          
<select disabled="disabled">    
@Html.DropDownListFor(
    model => model.EscalationQueue,
        new SelectList(Extensions.EscalationQueue, Model.EscalationQueue),
          new { @class = "escalation-queue", name = Model.EscalationQueue }
)  
</select>
.js file
var dropdownToggle = function () {
    $("input:checkbox").change(function () {
        if ($("input:checkbox").is(":checked")) {
            $("select").removeAttr("disabled");
        }
        else {
            $("select").attr("disabled", "disabled");
        }
    });
}

$(document).ready(function () {
    dropdownToggle();
});

Output:

Answers


You dont need the <select> tag, the HtmlHelper DropDownListFor will render that for you. If you want to initialize the dropdown as disabled set the html attribute as you did for declaring a cssclass...

<input type="checkbox" /> 
<p>check this box to escalate</p>  
@Html.DropDownListFor(
        model => model.EscalationQueue,
        new SelectList(Extensions.EscalationQueue, Model.EscalationQueue),
        new { @class = "escalation-queue", 
                name = Model.EscalationQueue, 
                disabled= "disabled" 
         }
)  

Need Your Help

Laravel-5 redirecting to /home after login

php laravel laravel-5 laravel-5.1

I'm building a custom authentication system with roles in Laravel-5.1.

Get only countries to autocomplete from Google Maps API

javascript google-maps google-maps-api-3

I'm using Google Maps API to get autocomplete list of cities and countries (without other details), and it works exellent.