title: MVC4 disable textbox on selection of a dropdownlist item
body: <p>I have a textbox and a dropdown on my form. When "MessageDate" item is selected from the dropdown the textbox should be disabled. The value for messageDate is stored in Viewbag in the controller</p>
  
  <p>Controller:</p>
  
  <pre><code>ViewBag.dd_search = dd_search;
  switch (dd_search)
  {
   ...
   case "msgDate":
       modelml = modelml.Where(m =&gt; m.Message_Date == Convert.ToDateTime(searchText)).ToList();
   break;
  }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>&lt;div class="col-md-2"&gt;
  @Html.TextBox("searchText", ViewBag.searchText as string, new { @class = "form-control" })                               
  &lt;/div&gt;
  &lt;div class="col-md-2"&gt;
   @Html.DropDownList("dd_search", new SelectList(EBA_AJAX.ViewModels.DropDown.DD_Message_Search(), "Value", "Text", ViewBag.dd_search), "--Select--", new { @class = "form-control" })
  
  &lt;/div&gt;
  </code></pre>
  
  <p>The javascript:</p>
  
  <pre><code>&lt;script&gt;
   $('#ddsearch').change(function ()
  {
      if ($(this).attr('@ViewBag.dd_search') == "msgDate")
      $("#txtsearch").attr('disabled', 'disabled');
      else
      $("#txtsearch").removeAttr('disabled');
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>I have used <a href="https://stackoverflow.com/questions/9234928/mvc3-lock-textbox-based-on-a-selection-on-a-dropdown-menu">this</a> post for reference but still not getting the desired output. Please help. Thanks.</p>