Link to home
Create AccountLog in
Avatar of solution1368
solution1368

asked on

asp.net, disable textbox, jquery

when the checkbox is checked, i would like to make the textbox = read only so the user can't type it. how can I do that?


<asp:CheckBox runat="server" ID="ProductionEquipmentCreateAnotherperiodTime" Text="Check to create another period time" /></td>
<asp:textbox runat="server" id="test" />
<script type="text/javascript">
    $("#<%=ProductionEquipmentCreateAnotherperiodTime.ClientID%>").change(function () {
        var rbvalue = $(this).is(":checked");
        if (rbvalue) {
            $('#<%= PanelProductionEquipmentCreateAnotherperiodTime.ClientID %>').show('slow');
        }
        else {
            $('#<%= PanelProductionEquipmentCreateAnotherperiodTime.ClientID %>').hide('slow');
        }

    });
</script>

<asp:Panel runat="server"   ID="PanelProductionEquipmentCreateAnotherperiodTime">
<asp:TextBox Width="200"  runat="server" ID="ProductEquipmentAnotherPeriodOfTime"></asp:TextBox>
</asp:Panel>
Avatar of leakim971
leakim971
Flag of Guadeloupe image

<script type="text/javascript">
    $("#<%=ProductionEquipmentCreateAnotherperiodTime.ClientID%>").change(function () {
        var rbvalue = $(this).is(":checked");
        if (rbvalue) {
            $('#<%= PanelProductionEquipmentCreateAnotherperiodTime.ClientID %>').show('slow');
            $("#<%= ProductEquipmentAnotherPeriodOfTim.ClientID %>").prop("readOnly", true);
        }
        else {
            $('#<%= PanelProductionEquipmentCreateAnotherperiodTime.ClientID %>').hide('slow');
            $("#<%= ProductEquipmentAnotherPeriodOfTim.ClientID %>").removeProp("readOnly");
        }

    });
</script>
.prop() and .removeProp() is available for jQuery 1.6+
else use : .attr("readOnly", "readOnly") and removeAttr("readOnly") if you have jQuery vesion under 1.6
Avatar of solution1368
solution1368

ASKER

and how to make the textbox = null?
$("#<%= ProductEquipmentAnotherPeriodOfTim.ClientID %>").prop("readOnly", true);
above working fine. but just want to make it value = "" as well when the checkbox is checked


https://www.experts-exchange.com/questions/27936450/asp-net-jquery-validation.html

more questions if you have time...
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account