tags:

views:

30

answers:

1

Hi,

I have a checkbox, a drop down list and a text box. I want to disable the drop down and text box on deselecting the checkbox. Following is what I have on my view -

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<%Html.CheckBox("chkCheckMe", new { enabled = Convert.ToBoolean(ViewData["ShowFlag"])}); %>>
<%Html.DropDownList("ddlModes", new SelectList(new string[]{"Auto", "Manual"}), new { enabled = Convert.ToBoolean(ViewData["ShowFlag"])}); %>
<%Html.TextBox("txtSample", new {enabled = Convert.ToBoolean(ViewData["ShowFlag"]) }); %>>
</asp:Content>

Can I do this using script?

Thanks, Kapil

A: 

This should get you started

<script type="text/javascript">
    window.onload = function() {
        var c = document.getElementById("yourCheckboxID");
        c.onclick = toggleElements;
    }
    function toggleElements() {
        var c = document.getElementById("yourCheckboxID");
        var d = document.getElementById("yourDropDownID");
        var t = document.getElementById("yourTextBoxID");
        d.disabled = t.disabled = c.checked;
    }
</script>
çağdaş